Python 2.4 | 7.3 The for statement
Hi My name is Juan Carlos Rodrigo, and I love Python. It is the most impressive and usefull language that I have ever seen. I am studing, at http://www.uoc.edu, an Information Technology Postgraduate. And I have programmed some REXX applications in my past Jobs (So I love python, no more ENDS). This is my Graduate final project http://ip.xpyro.com made in mod_python. I love mod_python too. Please don't crash my AMD making queries. :| --------8<--------8<--------8<--------8<--------8<--------8<-------- Python 2.4 | 7.3 The for statement: ----------------------------------- for_stmt ::= "for" target_list "in" expression_list ":" suite ["else" ":" suite] New for statement: ------------------ for_stmt ::= "for" target_list "in" expression_list [ "and" expression ] ":" suite ["else" ":" suite] ** If the expression evaluates to False before entering the for, jump else. ** If the expression is evaluated to False after the first iteration, break. So ¿What we can do with this new for?, and ¿It is going to avoid line exceed?: "My second remark is that our intellectual powers are rather geared to master static relations and that our powers to visualize processes evolving in time are relatively poorly developed." [1] It is easier if we see it beforehand: ------------------------------------- leave = False alist = [1,2,3,3,4,5,6,7,8,9] for item in alist and not leave: if item is 1: leave = True Avoiding code exceed: --------------------- a = 1 b = 2 c = 3 alist = [1,2,3,4,5,6,7,8,9] for item in alist and a < 2 and b < 3 and c < 4: if item == 3: a += 1 if item == 2: b += 1 if item == 1: c += 1 print "%d %d %d" % (a,b,c) # three lines off (25% less on breaks) Other features and the else: ---------------------------- alist = [1,2,3] enter = False if list[0] == 4: enter = True for item in alist and enter: print item else: print "No account" The real problem: ----------------- "The exercise to translate an arbitrary flow diagram more or less mechanically into a jump-less one, however, is not to be recommended." [1] Ok, it's not recommended, at large, but Python should make it possible, and then the people will choose. [1] Go To Statement Considered Harmful Edsger W. Dijkstra http://www.acm.org/classics/oct95/ PD: Your work is impressive, thanks. -- Juan Carlos Rodrigo Garcia. jrodrigog@gmail.com
Juan Carlos Rodrigo Garcia wrote:
It is easier if we see it beforehand: -------------------------------------
leave = False alist = [1,2,3,3,4,5,6,7,8,9] for item in alist and not leave: if item is 1: leave = True
Interesting idea, but not really needed given the existence of the break statement: for item in alist: if item is 1: break Cheers, Nick. -- Nick Coghlan | ncoghlan@email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net
On Sun, Mar 20, 2005, Juan Carlos Rodrigo Garcia wrote:
Hi My name is Juan Carlos Rodrigo, and I love Python. It is the most impressive and usefull language that I have ever seen.
Glad to hear that! However, your post is off-topic for python-dev; you'll have a better discussion posting to comp.lang.python. Thanks. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code -- not in reams of trivial code that bores the reader to death." --GvR
It is easier if we see it beforehand: -------------------------------------
leave = False alist = [1,2,3,3,4,5,6,7,8,9] for item in alist and not leave: if item is 1: leave = True
Apart from other objections, this is valid Python now, and failing with 'TypeError: iteration over non-sequence'. self.introduce: This is not my first Python-dev message, but I never have introduced myself so far. So: I began my career as a programmer in 1990 working with C and Unify Accell/SQL, and continued with various RDBMS systems (Ingres, Oracle) creating commercial tailor-made applications (CRM and ERP, but before these terms were coined AFAIK). However, since 1986 (during school) I helped older friends (students) with C programs on Unix systems (met Unix before IBM compatible machines). And I won't mention Sinclair ZX Spectrum and Sinclair QL use as a kid :) Along programming, I worked as a sysadm for my companies' systems (and as a support sysadm for clients' systems, including SysV/68k, Ultrix, AIX, HP-UX, SCO, Irix, and various Linux distros since 2.4 kernel), so I have a thorough shell scripting background. I never liked Perl when I found out about it, so I continued my awk usage. I also had a very good knowledge of Access 97 at the time (loved the data engine, hated the program itself). Python I met in 2000 as a script to analyse LaBrea tarpit logs, and reading the code instantly clicked for me (it was very close to the language I always intended to write myself RSN :). It was love at first code viewing. I have since become a Python advocate. Personal computer-related interests include image processing (and cataloguing), database design, game solving, "interconnected" generic information storage and retrieval (attempts in which will be superseded soon --hopefully-- by Chandler... :) My current employment as part of the customer support team for SGI systems in EMEA territory leaves little time for Python (attempts at social life worsens things too), and often enough this lack of time makes my posts to comp.lang.python somewhat sloppy... Though I won't ever be a called a *bot, I surely hope I can contribute a little. Thanks for reading!
for_stmt ::= "for" target_list "in" expression_list [ "and" expression ] ":" suite ["else" ":" suite]
It can't work. The expression_list could be just a variable, as could the expression, in which case you get "for" target_list "in" variable "and" variable ":" and, of course variable "and" variable is already an expression. So it's ambiguous.
participants (5)
-
Aahz
-
Andrew Koenig
-
Christos Georgiou
-
Juan Carlos Rodrigo Garcia
-
Nick Coghlan