Feature Requests item #1454344, was opened at 2006-03-20 09:24 Message generated for change (Comment added) made by gbrandl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1454344&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Interpreter Core Group: None >Status: Closed >Resolution: Rejected Priority: 5 Submitted By: kxroberto (kxroberto) Assigned to: Nobody/Anonymous (nobody) Summary: Make more out of 'as' : general ad-hoc right-assignment Initial Comment: "with EXPR as VAR" introduces 'as' as keyword. Occupying a new 2-letter kw, Python could maybe make more out of this: * it was often asked for transitive assignments to speed up the interrupted style of typing in Python * yet transitive left-assignments = += *= ... would indeed be an impact on pythonic discipline, create bad readable syntax, which can easyly be confused with == etc inside of Expressions. It would be not intuitive, with what value we are computing. Think e.g. of ugly things like: > a = ( 1+ (b.=2/x) ) Now trying a right-hand-assignment method using 'as' everywhere: > with open(x) as f: > f.write(s) > if re.search(x,s) as m: > print m.group(1) > elif re.search(y,s) as m: > print m.group(1) > while (x+1 as x) not in l: > do() > a = ( 1+ ( 2/x as b ) ), 2+b, 3+b > > print 'comment number', (id+1 as id) * I cannot see any uglyness in this kind of right-hand-assignment. Its intuitive 'english', speeds up typing tremendously, the computed thing on left side is still that, what is in the focus of reading. And maybe most important: it supports a natural evolutionary style of thinking: First you think about what you want compute in expressions, then you can store aside usefull stuff to somewhere happily. * 'as'-evolution with extra operator is not too tempting and clearly separated from the main = 'planning' doctrin * The operator priority of 'as' right-assignments should be higher than that of left-assignments and be next before brackets and commas. Execution order from left to right - that resolves as expected : > a += b as c > l=[ 1 as one, one+1 as two, {key as mykey:3 as three} ] > d=dict(var1=pi/2 as pi_2, ) The later 'as' would of course set pi_2 in caller's context. A transitive 'as' would be more important than having 'is' for the same as '=='. In fact, if "with .. as .." is possible, but "if .. as .." not, this would appear as broken syntax design to python newcomers. Robert ---------------------------------------------------------------------- >Comment By: Georg Brandl (gbrandl) Date: 2006-03-26 20:42 Message: Logged In: YES user_id=849994 Rejecting this for now. It has been proposed on python-dev, was not commented positively by Guido and won't be possible without a PEP. Regarding with .. as: In this context, "as" does _not_ assign the thing on its left to the name on its right. This would lead to at least some confusion if "if .. as" did this. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1454344&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com