Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
>>> I can't find a way to use an argument more than once, >>> without switching to "dictionary mode" and using keys for >>> everything. Even in "dictionary mode", the key is spelled more than once. The "tuple mode" below seems to save some typing.  However, when there are more and more item

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
>>   In that case you should re-think the delimiters, so that you have >>   something >> that can be nested.  An example (example only, I'm not in love with it > as >> a final form): Haven't really thought about that. Nesting is a big  issue if in the embedded expression, there is another  dyn

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
> Right, meaning that both have the same issues  > of performance, need for > str(), etc. There's absolutely no difference. OK, performance. Here is a new solution:   Suppose we have a new string method     str.format_join([...]) taking a list of strings and objects, with even-indexed ones being

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
> like this one ? > > b = dict(name="Sue", job="SAS sharp-shooter") > print "$b['name']$ works as b['job']" > > Is it really easier to read that the following ? > "{0} works as {1}".format(b['name'],b['job']) > > In the case in which b is an object having "job" and "name" > attribute, the dyna

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
... > That, by the way, is perhaps the biggest problem with this idea of  > dynamic strings: not that it is too powerful, but that it is TOO WEAK.  ... > and similar for both format() and Template. Seems you miss understood my notion of dynamic string. Dynamic strings are expressions in disguise

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
> "Are you %(name)s" % locals() # or vars() This partly solves the problem, however, you  can't work with expressions inside, like: > d"sin($x$) = $sin(x)$" Also, what if locals() or vars() does not contain the variable "x"? (x could be nonlocal or global). > It's more conservative than hos

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
>  "Are you "+name+"?" > > That allows arbitrary expressions and everything. >  To make that work for any type, you need: >>> "Are you "+ str(name) + "?" Another concern is performance. You are absolutely right, they are  equivalent in that both are expressions. As long as people start

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
> Actually, this sounds like a job for a precompiler/preprocessor. Do > whatever translations you want on your code, then turn it into a .py > file for execution. But hardly necessary, as there are already two - > err, three, I stand corrected - perfectly good ways to do it. Agree and disagree. 

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
- Original Message - > From: Steven D'Aprano > To: python-list@python.org > Cc: > Sent: Monday, April 2, 2012 4:26 PM > Subject: Re: string interpolation for python > > On Mon, 02 Apr 2012 00:39:42 -0700, Yingjie Lan wrote: > >>> You can alre

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
> Python already has *3* different built-in string > formatting/interpolation systems: ... > I would surmise that your key "implicitly grab variable values from > the enclosing scope" feature has previously been rejected for being > too magical. It grabs because it is an expression in disguise (n

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
> You can already do essentially that without adding a special-case string  > formatting method to the general methods we already have. > balls = 5 people = 3 'The {people} people have {balls} > balls.'.format(**locals()) > 'The 3 people have 5 balls.' Clearly dynamic strings

Re: string interpolation for python

2012-04-02 Thread Yingjie Lan
Hi Adrian, see my comments below. > > From: Adrian Hunt ... >It could break old code... okay you may say you should’nt allow >certain characters but if they're printable and used in a controlled >environment those characters can dramatically increase the security >

string interpolation for python

2012-03-30 Thread Yingjie Lan
Hi all,  I'd really like to share this idea of string interpolation for formatting. Let's start with some code: >>> name = "Shrek" >>> print( "Hi, $name$!") Hi, Shrek! >>> balls = 30 >>> print( "We have $balls$ balls.") We have 30 balls >>> persons = 5 >>> print ("And $persons$ persons.") And 5

the deceptive continuous assignments

2011-12-06 Thread Yingjie Lan
Hi, I just figured out this with Python3.2 IDLE: >>> class k: pass >>> x=k() >>> x.thing = 1 >>> x.thing 1 >>> x = x.thing = 1 Traceback (most recent call last):   File "", line 1, in     x = x.thing = 1 AttributeError: 'int' object has no attribute 'thing' >>> x 1 >>> when I do

Re: revive a generator

2011-10-21 Thread Yingjie Lan
- Original Message - > From: Chris Angelico > To: python-list@python.org > Cc: > Sent: Friday, October 21, 2011 4:27 PM > Subject: Re: revive a generator > > On Fri, Oct 21, 2011 at 7:02 PM, Yingjie Lan wrote: >> What if the generator involves a

Re: revive a generator

2011-10-21 Thread Yingjie Lan
- Original Message - > From: Paul Rudin > > I'm not really sure whether you intend g to yield the original values > after your "revive" or new values based on the new value of vo.  But > still you can make a class that supports the iterator protocol and does > whatever you want (but you

Re: revive a generator

2011-10-21 Thread Yingjie Lan
- Original Message - > From: Paul Rudin > To: python-list@python.org > Cc: > Sent: Friday, October 21, 2011 3:27 PM > Subject: Re: revive a generator > > > The language has no explicit notion of a request to "revive" a > generator. You could use the same syntax to make a new generator

Re: revive a generator

2011-10-21 Thread Yingjie Lan
- Original Message - > From: Paul Rudin > The language has no explicit notion of a request to "revive" a > generator. You could use the same syntax to make a new generator that > yeilds the same values as the one you started with if that's what you > want. > > As we've already discussed

Re: revive a generator

2011-10-21 Thread Yingjie Lan
> Here's an example of an explicit request to revive the generator: > g = (x*x for x in range(3)) for x in g: print x > 0 > 1 > 4 g = (x*x for x in range(3)) # revive the generator for x in g: print x #now this will work > 0 > 1 > 4 > > ChrisA What if the generator is p

Re: compare range objects

2011-10-20 Thread Yingjie Lan
- Original Message - > From: Westley Martínez > To: python-list@python.org > Cc: > Sent: Friday, October 21, 2011 12:22 AM > Subject: Re: compare range objects > > There's already a discussion about this on python-ideas.  But somebody > please tell me, why would you ever need to comp

Re: revive a generator

2011-10-20 Thread Yingjie Lan
- Original Message - > From: Paul Rudin > To: python-list@python.org > Cc: > Sent: Thursday, October 20, 2011 10:28 PM > Subject: Re: revive a generator > > Yingjie Lan writes: > >> Hi, >> >> it seems a generator expression can be us

compare range objects

2011-10-20 Thread Yingjie Lan
Hi,  Is it possible to test if two range objects contain the same sequence of integers by the following algorithm in Python 3.2? 1. standardize the ending bound by letting it be the first excluded integer for the given step size. 2. compare the standardized starting bound, ending bound and step

revive a generator

2011-10-20 Thread Yingjie Lan
Hi, it seems a generator expression can be used only once: >>> g = (x*x for x in range(3)) >>> for x in g: print x 0 1 4 >>> for x in g: print x #nothing printed >>> Is there any way to revive g here? Yingjie -- http://mail.python.org/mailman/listinfo/python-list

Re: How to test if object is an integer?

2011-10-17 Thread Yingjie Lan
- Original Message - > From: Noah Hall > To: MrPink > Cc: python-list@python.org > Sent: Tuesday, October 18, 2011 4:44 AM > Subject: Re: How to test if object is an integer? > There's the isdigit method, for example - > str = "1324325" str.isdigit() > True str = "

strange comparison result with 'is'

2011-10-17 Thread Yingjie Lan
Hi all,  This is quite strange when I used the Python shell with IDLE: >>> x = [] >>> id(getattr(x, 'pop')) == id(x.pop) True >>> getattr(x, 'pop') is x.pop False >>>  I suppose since the two things have the same id, the 'is'-test  should give a True value, but I get a False value.  Any partic

Re: [Python-ideas] allow line break at operators

2011-09-04 Thread Yingjie Lan
ith such a use case in mind. > >From: MRAB >To: python-list@python.org >Sent: Sunday, September 4, 2011 10:04 AM >Subject: Re: [Python-ideas] allow line break at operators > >On 04/09/2011 00:22, Yingjie Lan wrote: >>>  Every language with blocks needs some mechanis

Re: [Python-ideas] allow line break at operators

2011-09-03 Thread Yingjie Lan
Sunday, September 4, 2011 3:01 AM >Subject: Re: [Python-ideas] allow line break at operators > >On 9/3/2011 3:51 AM, Yingjie Lan wrote: >> I agree that long lines of code are not very common in many projects, >> though it might be the case with some heavily involved in math

Re: [Python-ideas] allow line break at operators

2011-09-03 Thread Yingjie Lan
. > >From: Yingjie Lan >To: Stephen J. Turnbull >Cc: python list ; Gabriel AHTUNE ; >python-ideas ; Matt Joiner >Sent: Saturday, September 3, 2011 6:33 PM >Subject: Re: [Python-ideas] allow line break at operators > > >Ambiguity: yes, when the last line of a suite

Re: [Python-ideas] allow line break at operators

2011-09-03 Thread Yingjie Lan
we can have such 'freedom' :) > >From: Stephen J. Turnbull >To: Yingjie Lan >Cc: Gabriel AHTUNE ; Matt Joiner ; >python-ideas >Sent: Saturday, September 3, 2011 5:29 PM >Subject: Re: [Python-ideas] allow line break at operators > >Yingjie Lan writes: > >&

Re: [Python-ideas] allow line break at operators

2011-09-03 Thread Yingjie Lan
that should not be hard. Again, my apology for top posting. > >From: Stephen J. Turnbull >To: Yingjie Lan >Cc: Gabriel AHTUNE ; Matt Joiner ; >"python-list@python.org" ; python-ideas > >Sent: Saturday, September 3, 2011 2:10 P

Re: [Python-ideas] allow line break at operators

2011-09-02 Thread Yingjie Lan
below.) > >From: Stephen J. Turnbull >To: Gabriel AHTUNE >Cc: Matt Joiner ; "python-list@python.org" >; python-ideas ; Yingjie Lan > >Sent: Friday, September 2, 2011 3:28 PM >Subject: Re: [Python-ideas] allow line break at operat

Re: [Python-ideas] allow line break at operators

2011-09-01 Thread Yingjie Lan
Joiner To: Yingjie Lan Cc: "python-list@python.org" ; python-ideas Sent: Friday, September 2, 2011 1:33 PM Subject: Re: [Python-ideas] allow line break at operators I guess the issue here is that you can't tell if an expression is complete without checking the indent of the followin

Re: [Python-ideas] allow line break at operators

2011-09-01 Thread Yingjie Lan
Hi Gabriel, == From: Gabriel AHTUNE Subject: Re: [Python-ideas] allow line break at operators So can be done with this syntax: > x = firstpart * secondpart  +  #line breaks here > anotherpart + #continue > stillanother #continue on. after a "

Re: [Python-ideas] allow line break at operators

2011-09-01 Thread Yingjie Lan
Hi Matt, === From: Matt Joiner The "trailing \" workaround is nonobvious. Wrapping in () is noisy and already heavily used by other syntactical structures.  === How about only require inden

Re: allow line break at operators

2011-08-12 Thread Yingjie Lan
From: Vito 'ZeD' De Tullio :umm... besides "notepad" pretty much any other serious "programmer editor" :program try to do its best to deal with line wrap: the minimal I found is :the wrapped line is "indented" at the same level of the flow, but I found :edi

Re: allow line break at operators

2011-08-12 Thread Yingjie Lan
> :The trouble of dealing with long lines can be avoided by a smart > :editor. It's called line wrap. > > Yeah, usually they just wrap it pretty arbitrarily, > and you don't have any control, isn't it? :umm... besides "notepad" pretty much any other serious "programmer editor" :program try to d

Re: allow line break at operators

2011-08-11 Thread Yingjie Lan
From: Chris Rebert To: Yingjie Lan Cc: "python-list@python.org" Sent: Thursday, August 11, 2011 3:50 PM Subject: Re: allow line break at operators On Thu, Aug 11, 2011 at 12:24 AM, Yingjie Lan wrote: > From: Steven D'Aprano > On Thu,

Re: allow line break at operators

2011-08-11 Thread Yingjie Lan
From: Steven D'Aprano To: python-list@python.org Sent: Thursday, August 11, 2011 12:18 PM Subject: Re: allow line break at operators On Thu, 11 Aug 2011 12:52 pm Yingjie Lan wrote: > :And if we require {} then truly free indentation should be OK

Re: allow line break at operators

2011-08-11 Thread Yingjie Lan
From: Michael Trausch To: Yingjie Lan Cc: Chris Angelico ; "python-list@python.org" Sent: Thursday, August 11, 2011 12:51 PM Subject: Re: allow line break at operators > Perhaps it could be made an optional thing to enable; for example, some &

Re: allow line break at operators

2011-08-10 Thread Yingjie Lan
On Wed, Aug 10, 2011 at 1:58 PM, Yingjie Lan wrote: > Is it possible for python to allow free splitting of single-line statements > without the backslashes, if we impose that expressions can only be split > when it is not yet a finished expression? :The trouble is that in a lot of c

Re: allow line break at operators

2011-08-10 Thread Yingjie Lan
:And if we require {} then truly free indentation should be OK too! But :it wouldn't be Python any more. Of course, but not the case with ';'. Currently ';' is optional in Python, But '{' is used for dicts. Clearly, ';' and '{' are different in magnitude. So the decision is: shall we change ';'

Re: allow line break at operators

2011-08-10 Thread Yingjie Lan
>> In terms of easier to read, I find code easier to read when the >> operators are at the beginnings of the lines (PEP 8 notwithstanding): >> >>    x = (someobject.somemethod(object3, thing) >>         + longfunctionname(object2) >>         + otherfunction(value1, value2, value3)) >> > > Without

Re: allow line break at operators

2011-08-10 Thread Yingjie Lan
> On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers > wrote: >> In terms of easier to read, I find code easier to read when the >> operators are at the beginnings of the lines (PEP 8 notwithstanding): >> >>    x = (someobject.somemethod(object3, thing) >>         + longfunctionname(object2) >>      

Re: allow line break at operators

2011-08-09 Thread Yingjie Lan
On Tue, Aug 9, 2011 at 9:42 PM, Yingjie Lan wrote: > Hi all, > > When writing a long expresion, one usually would like to break it into > multiple lines. Currently, you may use a '\' to do so, but it looks a little > awkward (more like machine-oriented thing). Theref

allow line break at operators

2011-08-09 Thread Yingjie Lan
Hi all, When writing a long expresion, one usually would like to break it into multiple lines. Currently, you may use a '\' to do so, but it looks a little awkward (more like machine-oriented thing). Therefore I start wondering why not allow line breaking at an operator, which is the standard w

anonymous function with multiple statements

2011-07-10 Thread Yingjie Lan
Hi all, I wonder if Python provides a way to define anonymous functions containing multiple statements? With lambda form, we can only define a function of a single expression. In Javascript, it is possible to define a full-fledged anonymous functions, which suggests it is useful to have it. I

Re: having both dynamic and static variables

2011-03-02 Thread Yingjie Lan
- Original Message From: Steven D'Aprano To: python-list@python.org Sent: Thu, March 3, 2011 1:27:01 PM Subject: Re: having both dynamic and static variables On Wed, 02 Mar 2011 19:45:16 -0800, Yingjie Lan wrote: > Hi everyone, > > Variables in Python are resolved

having both dynamic and static variables

2011-03-02 Thread Yingjie Lan
Hi everyone, Variables in Python are resolved dynamically at runtime, which comes at a performance cost. However, a lot of times we don't need that feature. Variables can be determined at compile time, which should boost up speed. Therefore, I wonder if it is a good idea to have static variable

the C header file when extending CPython

2011-01-11 Thread Yingjie Lan
Hi, I am wondering when extending Python (CPython), what should be put into the C header file? Any guidelines? Thanks, Yingjie -- http://mail.python.org/mailman/listinfo/python-list

Re: group 0 in the re module

2010-12-07 Thread Yingjie Lan
: Use \g<0>. Thanks! Though I wish all \1, \2, ..., should also be forbidden. Such a mixture of things looks like a patch work. No offense meant. Yingjie -- http://mail.python.org/mailman/listinfo/python-list

group 0 in the re module

2010-12-07 Thread Yingjie Lan
Hi, According to the doc, group(0) is the entire match. >>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist") >>> m.group(0) # The entire match 'Isaac Newton' But if you do this: >>> import re >>> re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234') '\x00 to 757-234' where I expected '7

Re: Python 3 encoding question: Read a filename from stdin, subsequently open that filename

2010-11-29 Thread Yingjie Lan
--- On Tue, 11/30/10, Dan Stromberg wrote: > In Python 3, I'm finding that I have encoding issues with > characters > with their high bit set.  Things are fine with strictly > ASCII > filenames.  With high-bit-set characters, even if I > change stdin's > encoding with: Co-ask. I have also had pro

Re: regular expression help

2010-11-29 Thread Yingjie Lan
--- On Tue, 11/30/10, goldtech wrote: > From: goldtech > Subject: regular expression help > To: python-list@python.org > Date: Tuesday, November 30, 2010, 9:17 AM > The regex is eating up too much. What I want is every > non-overlapping > occurrence I think. > > so rtt would be: > > '||flf

Re: what a cheap rule

2010-11-25 Thread Yingjie Lan
--- On Fri, 11/26/10, Steven D'Aprano wrote: > From: Steven D'Aprano > Subject: Re: what a cheap rule > To: python-list@python.org > Date: Friday, November 26, 2010, 5:10 AM > On Thu, 25 Nov 2010 08:15:21 -0800, > Yingjie Lan wrote: > > You seem to have mis

Re: tilted text in the turtle module

2010-11-25 Thread Yingjie Lan
--- On Fri, 11/26/10, Steve Holden wrote: > From: Steve Holden > Subject: Re: tilted text in the turtle module > To: python-list@python.org > Date: Friday, November 26, 2010, 4:16 AM > On 11/25/2010 5:58 PM, Yingjie Lan > wrote: > > --- On Thu, 11/25/10, Steve Holden &g

Re: the buggy regex in Python

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, MRAB wrote: > > > Look at the spans: > > >>> for m in re.finditer('((.d.)*)*', 'adb'): >     print(m.span()) > >     > (0, 3) > (3, 3) > > There's an non-empty match followed by an empty match. If you read my first post, it should be apparent that that the empty string

Re: tilted text in the turtle module

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, Steve Holden wrote: > > And even if I made a patch, > > then how to publish it? > > > Once you have a patch, attach it to the issue as a file and > try and get > it reviewed by a developer for incorporation into a future > release. > > Note that no Python 2.8 release is pl

Re: tilted text in the turtle module

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, Steve Holden wrote: > From: Steve Holden > Subject: Re: tilted text in the turtle module > To: python-list@python.org > Date: Thursday, November 25, 2010, 7:00 PM > On 11/25/2010 5:06 AM, Yingjie Lan > wrote: > This sounds like a good idea. To request a

Re: the buggy regex in Python

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, MRAB wrote: > re.findall performs multiple searches, each starting where > the previous > one finished. The first match started at the start of the > string and > finished at its end. The second match started at that point > (the end of > the string) and found another match,

Re: what a cheap rule

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, Steve Holden wrote: > > Sometimes the golden rule in Python of > > "explicit is better than implicit" is > > so cheap that it can be thrown away > > for the trouble of typing an empty tuple. > > > I'm not sure that there *are* any golden rules. The "Zen of > Python" is > inte

the buggy regex in Python

2010-11-25 Thread Yingjie Lan
I know many experts will say I don't have understanding...but let me pay this up front as my tuition. Here are some puzzling results I have got (I am using Python 3, I suppose similar results for python 2). When I do the following, I got an exception: >>> re.findall('(d*)*', 'adb') >>> re.finda

tilted text in the turtle module

2010-11-25 Thread Yingjie Lan
First of all, I'd like to express my deep gratidute to the author of this module, it is such a fun module to work with and to teach python as a first programming language. Secondly, I would like to request a feature if it is not too hard to achieve. Currently, you can only write texts horizonta

Re: a regexp riddle: re.search(r'

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, Phlip wrote: > From: Phlip > Subject: a regexp riddle: re.search(r' > To: python-list@python.org > Date: Thursday, November 25, 2010, 8:46 AM > HypoNt: > > I need to turn a human-readable list into a list(): > >    print re.search(r'(?:(\w+), |and > (\w+))+', 'whatever a,

what a cheap rule

2010-11-25 Thread Yingjie Lan
Sometimes the golden rule in Python of "explicit is better than implicit" is so cheap that it can be thrown away for the trouble of typing an empty tuple. Today when I am explaining that in Python 3, there are two ways to raise exceptions: raise Exception raise Exception() and that the first on

Re: Must be a bug in the re module [was: Why this result with the re module]

2010-11-04 Thread Yingjie Lan
--- On Wed, 11/3/10, MRAB wrote: > [snip] > The outer group is repeated, so it can match again, but the > inner group > can't match again because it captured all it could the > previous time. > > Therefore the outer group matches and captures an empty > string and the > inner group remembers its

Re: Must be a bug in the re module [was: Why this result with the re module]

2010-11-02 Thread Yingjie Lan
3, 2010, 8:43 AM > On 3/11/2010 4:23 AM, Yingjie Lan > wrote: > > --- On Wed, 11/3/10, MRAB  > wrote: > > > >> From: MRAB > >> Subject: Re: Must be a bug in the re module [was: > Why this result with the re module] > >> To: python-list@python.org &

Re: Must be a bug in the re module [was: Why this result with the re module]

2010-11-02 Thread Yingjie Lan
--- On Wed, 11/3/10, John Bond wrote: >3) then said there must be >=0 occurrences of what's inside it, >which of course there is, so that has no effect. > >((.a.)*)* Hi, I think there should be a difference: unlike before, now what's inside the outer group can match an empty s

Re: Must be a bug in the re module [was: Why this result with the re module]

2010-11-02 Thread Yingjie Lan
--- On Wed, 11/3/10, MRAB wrote: > From: MRAB > Subject: Re: Must be a bug in the re module [was: Why this result with the re > module] > To: python-list@python.org > Date: Wednesday, November 3, 2010, 8:02 AM > On 03/11/2010 03:42, Yingjie Lan > wrote: > Therefore th

Re: Must be a bug in the re module [was: Why this result with the re module]

2010-11-02 Thread Yingjie Lan
--- On Wed, 11/3/10, John Bond wrote: > Just to clarify - findall is returning: > > [ (only match in outer group, 1st match in inner group) > , (only match in outer group, 2nd match in inner group) > , (only match in outer group, 3rd match in inner group) > , (only match in outer group, 4th mat

Re: Must be a bug in the re module [was: Why this result with the re module]

2010-11-02 Thread Yingjie Lan
> Matches an empty string, returns '' > > The result is therefore ['Mar', '', '', 'lam', '', ''] Thanks, now I see it through with clarity. Both you and JB are right about this case. However, what if the regex is ((.a.)*)* ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Must be a bug in the re module [was: Why this result with the re module]

2010-11-02 Thread Yingjie Lan
> Your regex says "Zero or more consecutive occurrences of > something, always returning the most possible".  That's > what it does, at every position - only matching emptyness > where it couldn't match anything (findall then skips a > character to avoid overlapping/infinite empty > matches),  and

Must be a bug in the re module [was: Why this result with the re module]

2010-11-02 Thread Yingjie Lan
> From: John Bond > Subject: Re: Why this result with the re module > To: "Yingjie Lan" > Cc: python-list@python.org > Date: Tuesday, November 2, 2010, 8:09 PM > On 2/11/2010 12:19 PM, Yingjie Lan > wrote: > >> From: John Bond > >> Subject: R

Re: Why this result with the re module

2010-11-02 Thread Yingjie Lan
> From: Vlastimil Brom > Subject: Re: Why this result with the re module > in that case you may use re.finditer(...) Thanks for pointing this out. Still I'd love to see re.findall never discards the whole match, even if a tuple is returned. Yingjie -- http://mail.python.org/mailma

Re: Why this result with the re module

2010-11-02 Thread Yingjie Lan
> From: John Bond > Subject: Re: Why this result with the re module Firstly, thanks a lot for your patient explanation. this time I have understood all your points perfectly. Secondly, I'd like to clarify some of my points, which did not get through because of my poor presentation. I suggested

Re: Why this result with the re module

2010-11-02 Thread Yingjie Lan
> From: John Bond > You might wonder why something that can match no input > text, doesn't return an infinite number of those matches at > every possible position, but they would be overlapping, and > findall explicitly says matches have to be non-overlapping. That scrabbed my itches, though the

Re: Why this result with the re module

2010-11-02 Thread Yingjie Lan
> From: John Bond > Subject: Re: Why this result with the re module > re.findall('(.a.)*', 'Mary has a lamb') > > ['Mar', '', '', 'lam', '', ''] > So - see if you can explain the first "problematic" result > now. Thanks a lot for explaining to me the second "problematic" result! But the fir

Re: Why this result with the re module

2010-11-02 Thread Yingjie Lan
> From: John Bond > re.findall('(.a.)+', 'Mary has a lamb') > > ['Mar', 'lam'] > It's because you're using capturing groups, and because of > how they work - specifically they only return the LAST match > if used with repetition (and multiple matches occur). It seems capturing groups is ass

Why this result with the re module

2010-11-01 Thread Yingjie Lan
Hi, I am rather confused by these results below. I am not a re expert at all. the module version of re is 2.2.1 with python 3.1.2 >>> import re >>> re.findall('.a.', 'Mary has a lamb') #OK ['Mar', 'has', ' a ', 'lam'] >>> re.findall('(.a.)*', 'Mary has a lamb') #?? ['Mar', '', '', 'lam', '', ''

Allowing comments after the line continuation backslash

2010-10-31 Thread Yingjie Lan
Hi, Sorry if I am baking too many ideas today. I am just having trouble with the backslashes I would like to have comments after the line continuation backslash. >>> if a > 0 \ #comments for this condition and b > 0: #do something here This is currently not OK, but this might be a

Re: with block for multiple files

2010-10-31 Thread Yingjie Lan
> Guido's time machine strikes again! It's already in Python > 3; your > example would be spelled: > > with open('scores.csv') as f, open('grades.csv', wt) as g: >     g.write(f.read()) > Indeed! Thanks, Chris and James. Yingjie -- http://mail.python.org/mailman/listinfo/python-list

Allow multiline conditions and the like

2010-10-31 Thread Yingjie Lan
Hi, This is a mini-proposal I piggy-tailed in the other topic: Allow the conditions in the if-, elif-, while-, for-, and with-clauses to span multiple lines without using a backlalsh at the end of a line, just like when you specify literal lists, tuples, dicts, etc. across multiple lines (simila

with block for multiple files

2010-10-31 Thread Yingjie Lan
Hi, Suppose I am working with two files simultaneously, it might make sense to do this: with open('scores.csv'), open('grades.csv', wt) as f,g: g.write(f.read()) sure, you can do this with nested with-blocks, but the one above does not seem too complicated, it is like having a multiple as

Re: A bug for raw string literals in Py3k?

2010-10-31 Thread Yingjie Lan
> According to msg56377, the behaviour is "optimal" for regular > expressions. Well, I use regular expressions a lot, and I > still think it's a nuisance! Thanks for bringing that up. Using an otherwise 'dead' backlash to escape quotes in raw strings seems like the black magic of necromancy to

Re: A bug for raw string literals in Py3k?

2010-10-31 Thread Yingjie Lan
> > > All backslashes in raw string literals are > interpreted literally. > > > (seehttp://docs.python.org/release/3.0.1/whatsnew/3.0.html): > > > > All backslashes in syntactically-correct raw string > literals are interpreted literally. > > That's a good way of putting it. > Syntactical correc

Re: A bug for raw string literals in Py3k?

2010-10-31 Thread Yingjie Lan
> > So I suppose this is a bug? > > It's not, see > > http://docs.python.org/py3k/reference/lexical_analysis.html#literals > > # Specifically, a raw string cannot end in a single backslash Thanks! That looks weird to me ... doesn't this contradict with: All backslashes in raw string literals a

A bug for raw string literals in Py3k?

2010-10-31 Thread Yingjie Lan
Hi, I tried this in the IDLE (version 3.1.2) shell: >>> r'\' SyntaxError: EOL while scanning string literal But according to the py3k docs (http://docs.python.org/release/3.0.1/whatsnew/3.0.html): All backslashes in raw string literals are interpreted literally. So I suppose this is a bug? Y

Re: please help explain this result

2010-10-17 Thread Yingjie Lan
--- On Sun, 10/17/10, Steven D'Aprano wrote: > (1) If you assign to a variable *anywhere* in the function, > it is a local > *everywhere* in the function. > > There is no way to have a variable refer to a local in some > places of a > function and a global in other places of the same functi

Re: please help explain this result

2010-10-17 Thread Yingjie Lan
> From: Nobody > The determination of local or global is made when the "def" > statement is > executed, not when the function is called. Thanks a lot for your reply, which is of great help! So, I assume that when the 'def' is executed, any name occurred will be categorized as either local or

please help explain this result

2010-10-17 Thread Yingjie Lan
Hi, I played with an example related to namespaces/scoping. The result is a little confusing: >>> a=1 >>> def f(): a = a + 1 return a >>> f() I suppose I will get 2 ( 'a' is redefined as a local variable, whose value is obtained by the value of the global variable 'a' plus 1)

Re: solve alphametic puzzles in just 9 lines of code

2010-09-25 Thread Yingjie Lan
Sorry, didn't document my code well enough. Here is the code with an example. Yingjie #Code begins### from itertools import permutations def solve(puzzle): """solve alphametic puzzles in just 9 lines of code. Make sure each operator is seperated from the words by wh

Re: sequence multiplied by -1

2010-09-25 Thread Yingjie Lan
Hi all, Thanks for considering this proposal seriously and all your discussions shed light on the pro's and cons (well, more cons than pros, to be honest). It occurrs to me that this proposal is not a sound one, for the reasons already well documented in this thread, which I need not repeat.

solve alphametic puzzles in just 9 lines of code

2010-09-25 Thread Yingjie Lan
Hi, I am teaching Python this semester and as I am trying to explain the code by Raymond Hettinger, I need to make it simpler (this is an introductory course). And it ends up to be just 9 lines of code. Just for fun. See also: http://diveintopython3.org/advanced-iterators.html Regards, Yingji

Re: sequence multiplied by -1

2010-09-25 Thread Yingjie Lan
Hi, > > In my opinion this _isn't_ a situation where it's good. :) > >     L[::-1] > > is only marginally longer than > >     -1 * L > > I think this small gain doesn't justify "violating" this > "Python Zen" rule (from `import this`): > >     There should be one-- and preferably only one >

Re: sequence multiplied by -1

2010-09-25 Thread Yingjie Lan
--- On Sat, 9/25/10, Thomas Jollans wrote: > for every list l and integer n >= 0: >     len(l*n) == len(l)*n Well, this invariance is indeed broken under my proposal. But it is *already broken* in current python3k. However, the following invariance is maintained under my proposal: len(l*n) == le

sequence multiplied by -1

2010-09-25 Thread Yingjie Lan
Hi, I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a more meaningful symantics. Simply put, a sequence multiplied by -1 can give a reversed sequence. Then for any

Re: 3>0 is True

2010-09-15 Thread Yingjie Lan
> From: Jon Siddle > Subject: Re: 3>0 is True > To: python-list@python.org > Date: Wednesday, September 15, 2010, 5:04 PM >   As others have said, it's not > a matter of precendence. Using the > compiler module > you can see how python actually parses this: > > 3 > (0 is True) > Compare(Const(3)

3>0 is True

2010-09-15 Thread Yingjie Lan
Hi, I am not sure how to interprete this, in the interactive mode: >>> 3>0 is True False >>> (3>0) is True True >>> 3> (0 is True) True Why did I get the first 'False'? I'm a little confused. Thanks in advance for anybody who shed some light on this. YL -- http://mail.python.org/ma

empty set and empty dict for Python 3

2010-07-15 Thread Yingjie Lan
Hi there, Maybe somebody already suggested this: How about "{:}" for the empty dict, so that "{}" can denote the empty set? Yingjie -- http://mail.python.org/mailman/listinfo/python-list

ANN: expy 0.6.7 released!

2010-05-03 Thread Yingjie Lan
EXPY is an express way to extend Python! EXPY provides a way to extend python in an elegant way. For more information and a tutorial, see: http://expy.sourceforge.net/ I'm glad to announce a new release again today. ^_^ What's new: Version 0.6.7 1. Now functions can have 'value on failure'

Re: ANN: expy 0.6.6 released!

2010-05-02 Thread Yingjie Lan
> Subject: ANN: expy 0.6.6 released! > To: "python list" > Cc: "CAPI Python" > Date: Monday, May 3, 2010, 3:24 AM > EXPY is an express way to extend Python! > > EXPY provides a way to extend python in an elegant way. For > more information and a tutorial, see: http://expy.sourceforge.net/ > I'

  1   2   >