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

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 >

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
> 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
- 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
> 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
>  "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
> "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
... > 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
> 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
> 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
>>   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
>>> 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

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

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

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

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-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
: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
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-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-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: 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-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-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: [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: [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
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-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-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-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
. > >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
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-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

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

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

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: 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 = "

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

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

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

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-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: 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
- 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 > > 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: 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

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

announcement: expy release 0.5

2010-01-26 Thread Yingjie Lan
Hi all, This is to announce expy release 0.5. expy is an express way to extend Python. For more information and tutorials on expy, see: http://expy.sf.net/ Cheers, Yingjie -- http://mail.python.org/mailman/listinfo/python-list

mix statically typed with dynamically typed

2010-01-28 Thread Yingjie Lan
We all know that Python is dynamically typed, and dynamically typed languages are generally slower than statically typed ones. I wonder if it is possible at all for Python to mix statically-typed-ness with dynamically-typed-ness to boost up its speed a little bit, especially when speed is needed

expy 0.5.1 released

2010-02-01 Thread Yingjie Lan
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 -- http:/

expy 0.5.2 released

2010-02-02 Thread Yingjie Lan
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 -- http://mail.python.org/mailman/listinfo/python-list

Re: expy 0.5.2 released

2010-02-03 Thread Yingjie Lan
> > > > 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

expy 0.6 released

2010-02-10 Thread Yingjie Lan
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. Yo

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: 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,

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

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

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

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: 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: 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: 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 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: 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: 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: 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

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: 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

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

NameError: how to get the name?

2010-04-24 Thread Yingjie Lan
I wanted to do something like this: while True: try: def fun(a, b=b, c=c): pass except NameError as ne: name = get_the_var_name(ne) locals()[name] = '' else: break What's be best way to implement the function get_the_var_name(ne) that returns the name of the variable that could

Re: NameError: how to get the name?

2010-04-24 Thread Yingjie Lan
--- On Sat, 4/24/10, Steven D'Aprano wrote: > From: Steven D'Aprano > Subject: Re: NameError: how to get the name? > To: python-list@python.org > Date: Saturday, April 24, 2010, 4:07 PM > On Sat, 24 Apr 2010 04:19:43 -0700, > Yingjie Lan wrote: > > &g

Re: NameError: how to get the name?

2010-04-24 Thread Yingjie Lan
--- On Sat, 4/24/10, James Mills wrote: > From: James Mills > Subject: Re: NameError: how to get the name? > To: "Yingjie Lan" > Cc: "python list" > Date: Saturday, April 24, 2010, 4:03 PM > On Sat, Apr 24, 2010 at 9:19 PM, > Yingjie Lan > w

Re: NameError: how to get the name?

2010-04-24 Thread Yingjie Lan
--- On Sat, 4/24/10, Gary Herron wrote: > From: Gary Herron > Subject: Re: NameError: how to get the name? > To: > Cc: python-list@python.org > Date: Saturday, April 24, 2010, 8:03 PM > Yingjie Lan wrote: > > --- On Sat, 4/24/10, Steven D'Aprano > wrote: > &

Re: NameError: how to get the name?

2010-04-24 Thread Yingjie Lan
--- On Sun, 4/25/10, Chris Rebert wrote: > From: Chris Rebert > Subject: Re: NameError: how to get the name? > To: "Yingjie Lan" > Cc: python-list@python.org > Date: Sunday, April 25, 2010, 3:27 AM > On Sat, Apr 24, 2010 at 4:17 PM, > Yingjie Lan > wrote: &g

Re: NameError: how to get the name?

2010-04-24 Thread Yingjie Lan
--- On Sun, 4/25/10, Chris Rebert wrote: > From: Chris Rebert > Subject: Re: NameError: how to get the name? > To: "Yingjie Lan" > Cc: "python list" > Date: Sunday, April 25, 2010, 10:09 AM > On Sat, Apr 24, 2010, Yingjie Lan > > wrote: > > O

ANN: expy 0.6.4 released!

2010-04-25 Thread Yingjie Lan
expy is an express way to extend python. I have been using this in a big project and the outcome is quite satisfying. What's New: 1. now generated header files are separate from implementation files. 2. bug fixes. 3. updated documentation. For more information: http://expy.sourceforge.net/ C

ANN: expy 0.6.4 released!

2010-04-26 Thread Yingjie Lan
expy is an express way to extend python. It is written in pure python and very light weight. I have been using this in a big project and the outcome is quite satisfying. What's New: 1. now generated header files are separate from implementation files. 2. bug fixes. 3. updated documentation. F

SWIG + expy

2010-04-26 Thread Yingjie Lan
Hi, Is it possible to use SWIG to parse C/C++, and provide an interface for me to generate some code? I thought it might be good to have SWIG help generate expy (see http://expy.sourceforge.net) files, then generate the python extension via expy. Yingjie -- http://mail.python.org/mai

Re: SWIG + expy

2010-04-27 Thread Yingjie Lan
> From: Stefan Behnel > Subject: Re: SWIG + expy > To: python-list@python.org > Date: Tuesday, April 27, 2010, 11:57 AM > Yingjie Lan, 27.04.2010 08:30: > > Is it possible to use SWIG to parse C/C++, and provide > an interface for > > me to generate some code? I thou

ANN: expy 0.6.5 released!

2010-04-30 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/ What's new: 1. Correct treatment of __init__ method. 2. Give warnings of missing Py_INCREF on appropriate special type met

ANN: expy 0.6.6 released!

2010-05-02 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/ What's new: 1. Special methods can now take @throws decorators. 2. Added convenience macros _NEW and _CheckExact for extension

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'

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'

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

using expy to extend python

2009-08-05 Thread Yingjie Lan
Hi, The expy project provides an express way to extend Python. After some careful considerations, I came up with some reasons for expy (this is not an exhaustive list): (I). WYSIWYG. The expy project enables you to write your module in Python the way your extension would be (WYSIWYG), and mea

Re: using expy to extend python

2009-08-05 Thread Yingjie Lan
> From: Wolfgang Rohdewald > Subject: Re: using expy to extend python > To: python-list@python.org > Date: Thursday, August 6, 2009, 3:48 AM > On Thursday 06 August 2009, Yingjie > Lan wrote: > > For more information about expy, please visit its > homepage at: > &g

releasing expy 0.1.1

2009-08-11 Thread Yingjie Lan
Hi all, This is to announce the release of expy 0.1.1 for those who are interested. Thanks a lot for the interest from this list. For more information, please see http://expy.sf.net/ Note: expy is an express way to extend Python. Why consider expy? Here are some good reasons: (I). WYSIWYG.

Re: [Python-Dev] expy: an expressway to extend Python

2009-08-14 Thread Yingjie Lan
--- On Sat, 8/8/09, Stefan Behnel wrote: > From: Stefan Behnel > Subject: Re: [Python-Dev] expy: an expressway to extend Python > To: python-...@python.org > Date: Saturday, August 8, 2009, 4:55 PM > > More details at http://expy.sourceforge.net/ > > I'm clearly biased, but my main concern here

expy 0.1.2 released!

2009-09-04 Thread Yingjie Lan
Hi, This is to announce the release of expy 0.1.2 What's new? -- 1. allow both keywords and positional arguments to functions/methods. 2. allow wrapping up your returned value by yourself. (example is provided in tutorial) What is expy? -- expy is an expressway to exte

expy 0.1.3 released!

2009-09-07 Thread Yingjie Lan
Hi, This is to announce the release of expy 0.1.3 Now this release support class members/fields besides instance members/fields of extension types. What is expy? -- expy is an expressway to extend Python! For more details on expy: http://expy.sf.net/ Thanks! Yingjie --

expy 0.2 released!

2009-09-21 Thread Yingjie Lan
Hi, This is to announce the release of expy 0.2. What's new? 1. fixed the 'const char*' bug. 2. introduced the 'raw_type'. What is expy? -- expy is an expressway to extend Python! For more details, visit http://expy.sf.net/ Have a nice one! Yingjie --

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

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)

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: 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

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 >

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 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.

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

  1   2   >