Re: Python & Go

2009-11-16 Thread Graham Breed
Terry Reedy wrote: It seems to me that generators are already 'channels' that connect the calling code to the __next__ method, a semi-coroutine based on the body of the generator function. At present, the next method waits until an object is requested. Then it goes into action, yields an objec

Re: The future of Python immutability

2009-09-07 Thread Graham Breed
John Nagle wrote: In the beginning, strings, tuples, and numbers were immutable, and everything else was mutable. That was simple enough. But over time, Python has acquired more immutable types - immutable sets and immutable byte arrays. Each of these is a special case. Immutabil

Re: Regular Expression Help

2009-04-12 Thread Graham Breed
Jean-Claude Neveu wrote: Hello, I was wondering if someone could tell me where I'm going wrong with my regular expression. I'm trying to write a regexp that identifies whether a string contains a correctly-formatted currency amount. I want to support dollars, UK pounds and Euros, but the exam

Re: Correct URL encoding

2009-03-15 Thread Graham Breed
mattia wrote: I'm using urlopen in order to download some web pages. I've always to replace some characters that are in the url, so I've come up with: url.replace("|", "%7C").replace("/", "%2F").replace(" ", "+").replace (":", "%3A") There isn't a better way of doing this? Yeah, shame there's

Re: Get bound method by name

2009-03-03 Thread Graham Breed
Johannes Bauer wrote: Hello group, I'm looking for a Python function but have forgotten it's name. Essentially what I want is: class Foo(): def bar(self): pass x = Foo() y = x.MAGIC("bar") print(y) > So the question is: How is the magic function called which returns me

Re: Is using range() in for loops really Pythonic?

2008-05-16 Thread Graham Breed
George Sakkis wrote: If you push this logic too far, you should del every name immediately after the last statement it is used in the scope. I would generally find less readable some code spread with del every few lines, micro- managing the effective scope of each name. YMMV. Yes, but ... how

Re: Python 2.5 adoption

2008-04-19 Thread Graham Breed
On Apr 19, 3:16 am, Joseph Turian <[EMAIL PROTECTED]> wrote: > Basically, we're planning on releasing it as open-source, and don't > want to alienate a large percentage of potential users. How about Java users? Jython was recently at 2.2 (still is for all I know). I'm pleased they've got that fa

Re: Rounding a number to nearest even

2008-04-11 Thread Graham Breed
On Apr 11, 6:14 pm, bdsatish <[EMAIL PROTECTED]> wrote: > The built-in function round( ) will always "round up", that is 1.5 is > rounded to 2.0 and 2.5 is rounded to 3.0. > > If I want to round to the nearest even, that is > > my_round(1.5) = 2# As expected > my_round(2.5) = 2# Not

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Graham Breed
Dennis Lee Bieber wote: > But if these "macros" are supposed to allow one to sort of extend > Python syntax, are you really going to code things like > > macrolib1.keyword > > everywhere? I don't see why that *shouldn't* work. Or "from macrolib1 import keyword as foo". And to be tru

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-26 Thread Graham Breed
Douglas Alan wote: > Graham Breed <[EMAIL PROTECTED]> writes: > > > Another way is to decorate functions with their local variables: > > >>>> from strict import my > >>>> @my("item") > > ... def f(x=1, y=2.5, z=[1,2,4]): > >

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-24 Thread Graham Breed
Steven D'Aprano wote: > But if you really want declarations, you can have them. > > >>> import variables > >>> variables.declare(x=1, y=2.5, z=[1, 2, 4]) > >>> variables.x = None > >>> variables.w = 0 > Traceback (most recent call last): > File "", line 1, in > File "variables.py", line 15, i

Re: Trivial string substitution/parser

2007-06-19 Thread Graham Breed
Duncan Booth wote: > If you must insist on using backslash escapes (which introduces the > question of how you get backslashes into the output: do they have to be > escaped as well?) then use string.Template with a custom pattern. If anybody wants this, I worked out the following regular expressi

Re: Trivial string substitution/parser

2007-06-18 Thread Graham Breed
f he really does want to reject single letter variable names, or names beginning with a backslash, he'll still need to subclass Template and supply a regular expression, but a simpler one. > ... and in another message Graham Breed wrote: > > def get_variable(varname): > >

Re: Trivial string substitution/parser

2007-06-17 Thread Graham Breed
Samuel wote: > Thanks, however, turns out my specification of the problem was > incomplete: In addition, the variable names are not known at compilation > time. > I just did it that way, this looks fairly easy already: > > --- > import re > > def variable_sub_cb(match): >

Re: Pyrex speed

2006-05-27 Thread Graham Breed
Jim Lewis \/\/|20+3: > I'm not planning to write C functions. My understanding is that by > using cdefs in the python code one can gain substantial speed. I'm > trying to find a description of how to modify python code in more > detail so it runs fast under pyrex. I've used pyrex to speed up my co