Re: goto statement
Grant Edwards [EMAIL PROTECTED] writes: On 2005-04-21, Sergei Organov [EMAIL PROTECTED] wrote: Well, I'm writing for embedded realtime systems in C/C++ and have never encountered a single need to use goto. I have encountered situations in C programs where the best thing to use was a goto. Those situations have always been handled beutifully by a raise in Python. setjmp/longjump? -- Sergei. -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 2005-04-21, Sergei Organov [EMAIL PROTECTED] wrote: Grant Edwards [EMAIL PROTECTED] writes: On 2005-04-21, Sergei Organov [EMAIL PROTECTED] wrote: Well, I'm writing for embedded realtime systems in C/C++ and have never encountered a single need to use goto. I have encountered situations in C programs where the best thing to use was a goto. Those situations have always been handled beutifully by a raise in Python. setjmp/longjump? I've always found setjmp/longjmp much more confusing and hard to maintain than a simple goto. It also requires library support that goto doesn't. -- Grant Edwards grante Yow! Your CHEEKS sit like at twin NECTARINES above visi.coma MOUTH that knows no BOUNDS -- -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Grant Edwards [EMAIL PROTECTED] writes: On 2005-04-21, Sergei Organov [EMAIL PROTECTED] wrote: Grant Edwards [EMAIL PROTECTED] writes: On 2005-04-21, Sergei Organov [EMAIL PROTECTED] wrote: Well, I'm writing for embedded realtime systems in C/C++ and have never encountered a single need to use goto. I have encountered situations in C programs where the best thing to use was a goto. Those situations have always been handled beutifully by a raise in Python. setjmp/longjump? I've always found setjmp/longjmp much more confusing and hard to maintain than a simple goto. It also requires library support that goto doesn't. Agreed. The 'goto error' idiom is in fact the only goto usage I do agree with provided there is no support for exceptions, but that's not applicable to Python anyway. -- Sergei. -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov schrieb: but what if i just can't to do this becouse i'm working thrue ssh, and have to use only installed editors (such as vi) - at first line of block enter: ma (mark line as 'a') - go to last line of block - enter :'a,.s/^/###/ (insert 3 comment chars at begin of line, starting from line marked as 'a' to current line) :) -- --- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') --- -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 2005-04-21, Sergei Organov [EMAIL PROTECTED] wrote: Well, I'm writing for embedded realtime systems in C/C++ and have never encountered a single need to use goto. I have encountered situations in C programs where the best thing to use was a goto. Those situations have always been handled beutifully by a raise in Python. setjmp/longjump? I've always found setjmp/longjmp much more confusing and hard to maintain than a simple goto. It also requires library support that goto doesn't. Agreed. The 'goto error' idiom is in fact the only goto usage I do agree with provided there is no support for exceptions, but that's not applicable to Python anyway. Exactly. I've been writing C code for 20+ years, and the only problems where I found goto to be a good solution are the ones where exceptions are even better solutions in Python. I've never found myself wishing for a goto when writing Python code. -- Grant Edwards grante Yow! It's hard being at an ARTIST!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 2005-04-21, Peter Maas [EMAIL PROTECTED] wrote: Maxim Kasimov schrieb: but what if i just can't to do this becouse i'm working thrue ssh, and have to use only installed editors (such as vi) - at first line of block enter: ma (mark line as 'a') - go to last line of block - enter :'a,.s/^/###/ (insert 3 comment chars at begin of line, starting from line marked as 'a' to current line) Sure, but what about the case where his program is on paper tape and all he has for an editor is an ice pick? -- Grant Edwards grante Yow! Kids, don't gross me at off... Adventures with visi.comMENTAL HYGIENE can be carried too FAR! -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Grant Edwards [EMAIL PROTECTED] wrote: Sure, but what about the case where his program is on paper tape and all he has for an editor is an ice pick? Can't you emulate that in emacs with M-X inclusive-or-overwrite-mode? -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Grant Edwards [EMAIL PROTECTED] writes: On 2005-04-21, Peter Maas [EMAIL PROTECTED] wrote: Maxim Kasimov schrieb: but what if i just can't to do this becouse i'm working thrue ssh, and have to use only installed editors (such as vi) - at first line of block enter: ma (mark line as 'a') - go to last line of block - enter :'a,.s/^/###/ (insert 3 comment chars at begin of line, starting from line marked as 'a' to current line) Sure, but what about the case where his program is on paper tape and all he has for an editor is an ice pick? Then inserting goto doesn't seem to be an acceptable option either ;) -- Sergei. -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Hi, Have you tried the triple quote comment technique? I am assuming you want to skip some code for the time being. Here is an example print hello world ''' COMMENT OUT FOR NOW someFunction() someOtherFunction() ''' print goodbye world This means that you have only two locations to remove the blocked out code. This is identical to having to remove the goto statement and the marker. Hope that helps. -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
pythonUser_07 wrote: Hi, Have you tried the triple quote comment technique? I am assuming you want to skip some code for the time being. Here is an example print hello world ''' COMMENT OUT FOR NOW someFunction() someOtherFunction() ''' print goodbye world This means that you have only two locations to remove the blocked out code. This is identical to having to remove the goto statement and the marker. Hope that helps. how do use this here: print hello world ... ... ... sql = ''' some long query ''' ... ... ... sql = another query ... ... ... print goodbye world -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov wrote: how do use this here: are you still claiming you're not a troll? *plonk* /F -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov wrote: how do use this here: print hello world There are cases when you can't do it in any language. php: /* this is a debug comment function1(); function2(); /* this is a normal multiline comment block it ends here */ function3(); */ end of debug comment / if you don't really want to do it / Mage -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On Thursday 21 April 2005 17:42, Maxim Kasimov wrote: Have you tried the triple quote comment technique? how do use this here: Simple. sql = ''' some long query ''' Change this to: sql = some long query since you shouldn't be using multiple quoting styles in one module, any more than you should be using multiple casing styles. Then just put single quotes around the place where you want to comment. Not hard, is it? james. pgpEOkrYjHYZq.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 2005-04-21, Roy Smith [EMAIL PROTECTED] wrote: Grant Edwards [EMAIL PROTECTED] wrote: Sure, but what about the case where his program is on paper tape and all he has for an editor is an ice pick? Can't you emulate that in emacs with M-X inclusive-or-overwrite-mode? Heck, emacs probably has a paper-tape-mode where it displays the file like this: ooo. ooo. ooo. ooo. o o.o o o o.oo oo. oo o .oo o ooo. o.oo oo.oo o o o.o oo o .ooo If not, i'm sure it'll soon be added. -- Grant Edwards grante Yow! I'm losing my at hair...did it go to visi.comATLANTIC CITY?? -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 2005-04-21, Sergei Organov [EMAIL PROTECTED] wrote: Grant Edwards [EMAIL PROTECTED] writes: On 2005-04-21, Peter Maas [EMAIL PROTECTED] wrote: Maxim Kasimov schrieb: but what if i just can't to do this becouse i'm working thrue ssh, and have to use only installed editors (such as vi) - at first line of block enter: ma (mark line as 'a') - go to last line of block - enter :'a,.s/^/###/ (insert 3 comment chars at begin of line, starting from line marked as 'a' to current line) Sure, but what about the case where his program is on paper tape and all he has for an editor is an ice pick? Then inserting goto doesn't seem to be an acceptable option either ;) Scissors, tape, and a box full of prepunched goto and label statements. Of course you could do the same with a bunch of pre-punched tape-chunks. -- Grant Edwards grante Yow! Yow! Am I in at Milwaukee? visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Hi All-- Fredrik Lundh wrote: Maxim Kasimov wrote: how do use this here: are you still claiming you're not a troll? *plonk* Oh, I don't think he's a troll, but his license to use Python should be revoked. I think RPG would be a good language for him, don't you? Metta, Ivan -- Ivan Van Laningham God N Locomotive Works http://www.andi-holmes.com/ http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Grant Edwards wrote: On 2005-04-21, Sergei Organov [EMAIL PROTECTED] wrote: Well, I'm writing for embedded realtime systems in C/C++ and have never encountered a single need to use goto. I have encountered situations in C programs where the best thing to use was a goto. Those situations have always been handled beutifully by a raise in Python. setjmp/longjump? I've always found setjmp/longjmp much more confusing and hard to maintain than a simple goto. It also requires library support that goto doesn't. Agreed. The 'goto error' idiom is in fact the only goto usage I do agree with provided there is no support for exceptions, but that's not applicable to Python anyway. Exactly. I've been writing C code for 20+ years, and the only problems where I found goto to be a good solution are the ones where exceptions are even better solutions in Python. I've never found myself wishing for a goto when writing Python code. I can remember in the early apple2+ days of trying to untangle code written by others with liberal use of gotos and no clear program structure. A non trivial task that often meant it was easier to start over than to modify someone elses program. Determining the context of a statement often required snaking through several dozen gotos with 'line number's to find out what a particular section of code actually did. Making changes to such code could be difficult and often had unintended consequences. The if, elif, else, functions, and while statements are the replacements for goto's. And they make the code much more readable and understandable than something like ... 100 PRINT HELLO 105 INPUT ;S$ 110 IF S$ = GOODBYE THEN GOTO 140 115 IF S$ = HOW ARE YOU THEN GOTO 150 130 GOTO 100 140 PRINT GOODBYE 145 GOTO 200 150 PRINT I'M FINE 160 GOTO 105 200 REM CONTINUE LOL, I HAD TO... Oops caps... look up apple soft basic to remember what I couldn't do. Part of the reason for the spaghetti code was that with line numbers it's easier to tack on something to the end than it is to change all the line numbers if you didn't allow for room. I for one, don't miss goto's or line numbers! ;-) Apple Soft Quick Refrence - http://www.cosmicwolf.com/AppleII/applesoft_basic.htm Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
praba kar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Dear All, In Python what is equivalent to goto statement Sheesh! It took 20 days for this to get to my mail server! John Roth regards, praba -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
praba kar wrote: Dear All, In Python what is equivalent to goto statement You shouldn't use goto in high-level languages. Mage -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 4/20/05, praba kar [EMAIL PROTECTED] wrote: In Python what is equivalent to goto statement http://docs.python.org/tut/node6.html See, it's those dratted node numbers again. ;-) -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Simon Brunning a écrit : On 4/20/05, praba kar [EMAIL PROTECTED] wrote: In Python what is equivalent to goto statement http://docs.python.org/tut/node6.html See, it's those dratted node numbers again. ;-) other equivalents are in http://docs.python.org/tut/node10.html -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 4/20/05, Maurice Caret [EMAIL PROTECTED] wrote: other equivalents are in http://docs.python.org/tut/node10.html I also missed http://docs.python.org/tut/node5.html#SECTION00520, for the while statement. Those URLs just keeg getting better... -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Mage wrote: praba kar wrote: Dear All, In Python what is equivalent to goto statement You shouldn't use goto in high-level languages. it would be quite useful for debuging porposes -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote: it would be quite useful for debuging porposes How does goto help you to remove bugs? I can certainly see how it helps you put them in in the first place... -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Mage wrote: praba kar wrote: Dear All, In Python what is equivalent to goto statement You shouldn't use goto in high-level languages. Nonsense -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
John Bokma wrote: Mage wrote: praba kar wrote: Dear All, In Python what is equivalent to goto statement You shouldn't use goto in high-level languages. Nonsense Thank you! Above all your claim is well justified. These brilliant arguments you have put forth really explain in a magnificent way why goto is a sane addition to any HLL. Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Simon Brunning wrote: On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote: it would be quite useful for debuging porposes How does goto help you to remove bugs? I can certainly see how it helps you put them in in the first place... if you need to comment a couple of code (and then uncomment ), what are you doing then? -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov wrote: Simon Brunning wrote: On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote: it would be quite useful for debuging porposes How does goto help you to remove bugs? I can certainly see how it helps you put them in in the first place... if you need to comment a couple of code (and then uncomment ), what are you doing then? Use comments? -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Robert Kern wrote: Maxim Kasimov wrote: Simon Brunning wrote: On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote: it would be quite useful for debuging porposes How does goto help you to remove bugs? I can certainly see how it helps you put them in in the first place... if you need to comment a couple of code (and then uncomment ), what are you doing then? Use comments? WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov wrote: Robert Kern wrote: Maxim Kasimov wrote: Simon Brunning wrote: On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote: it would be quite useful for debuging porposes How does goto help you to remove bugs? I can certainly see how it helps you put them in in the first place... if you need to comment a couple of code (and then uncomment ), what are you doing then? Use comments? WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows Use multi-line string literals. ''' This whole 'code' is commented out, and you can use every type of quote except three singles. ''' Or, if you really like the spirit of goto, use if 0:. Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov wrote: WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows There are editors that can comment and uncomment blocks. In worst case you can use to comment blocks (not elegant but works). Mage -- http://mail.python.org/mailman/listinfo/python-list
RE: goto statement
On 4/20/05, praba kar [EMAIL PROTECTED] wrote: In Python what is equivalent to goto statement An old user-friendly cartoon that might be relevant: http://ars.userfriendly.org/cartoons/?id=2506 Have fun :-) Sander -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote: WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows Get a decent text editor. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
+1 Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Hallchen! Maxim Kasimov [EMAIL PROTECTED] writes: [...] WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows Then just use a good editor. Tsch, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
praba kar wrote: In Python what is equivalent to goto statement http://groups-beta.google.com/group/comp.lang.python/msg/98264a0daa007c46 -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Use multi-line string literals. ''' it will not help if there is another ''' or/and inside of code block This whole 'code' is commented out, and you can use every type of quote except three singles. ''' Or, if you really like the spirit of goto, use if 0:. ... and add tabs to each string Reinhold -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Torsten Bronger wrote: Hallchen! Maxim Kasimov [EMAIL PROTECTED] writes: [...] WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows but what if i just can't to do this becouse i'm working thrue ssh, and have to use only installed editors (such as vi) -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote: Or, if you really like the spirit of goto, use if 0:. ... and add tabs to each string Get a decent text editor. What are you using? Notepad? -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov wrote: Torsten Bronger wrote: Hallchen! Maxim Kasimov [EMAIL PROTECTED] writes: WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows but what if i just can't to do this becouse i'm working thrue ssh, and have to use only installed editors (such as vi) Surely you use more than one-character indents? If that's so, you can just insert the if 0: using, say, two characters indentation instead of the usual four. Then the following four-character-indented code is removed. Alternatively, use ''' and ''' surrounding the code block and it will be ignored. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Peter Hansen wrote: Maxim Kasimov wrote: Torsten Bronger wrote: Hallchen! Maxim Kasimov [EMAIL PROTECTED] writes: WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows but what if i just can't to do this becouse i'm working thrue ssh, and have to use only installed editors (such as vi) Surely you use more than one-character indents? If that's so, you can just insert the if 0: using, say, two characters indentation instead of the usual four. Then the following four-character-indented code is removed. Alternatively, use ''' and ''' surrounding the code block and it will be ignored. f..., i don't requesting that goto was available in next versions of python, but i'm saying if it will be so, it will be easy and quickly _debug_ some skripts, _not only_ for commenting -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov wrote: Use multi-line string literals. ''' it will not help if there is another ''' or/and inside of code block Yes, but how often do you use them? And aren't you consistent in the choice of your quotes? This whole 'code' is commented out, and you can use every type of quote except three singles. ''' Or, if you really like the spirit of goto, use if 0:. ... and add tabs to each string Yes. Where's the problem? M-x indent-region-ly yours, Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov wrote: f..., i don't requesting that goto was available in next versions of python, but i'm saying if it will be so, it will be easy and quickly _debug_ some skripts, _not only_ for commenting If you want, you can always use the goto module. Reinhold, no, I will not tell you where to find it -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On Wed, 20 Apr 2005 14:58:35 +0300, rumours say that Maxim Kasimov [EMAIL PROTECTED] might have written: if you need to comment a couple of code (and then uncomment ), what are you doing then? Use comments? WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows What editor exactly are you using that can't un/indent and un/comment a block of lines? Obviously, neither vi, nor emacs, nor idle. -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On Wed, 20 Apr 2005 16:13:32 +0300, rumours say that Maxim Kasimov [EMAIL PROTECTED] might have written: but what if i just can't to do this becouse i'm working thrue ssh, and have to use only installed editors (such as vi) If you use plain vi (not vim) and you want to comment e.g. 5 lines of code, go to the first of these five and: - if autoindent type: 5O^Dif 0:{ESC} ^D above is Ctrl-D, {ESC} is your Escape key - if noautoindent type: YP^Cif 0:{ESC}j5 ^C above is literal ^, literal C, *NOT* Ctrl-C; {ESC} is your Escape key To control autoindent, you can type: :se ai or :se noai If you need more help, I would gladly send you the output of `man vi' from a non-GNU Unix. I can also send you the output of `man vim' from a GNU system. -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 4/20/05, Christos TZOTZIOY Georgiou [EMAIL PROTECTED] wrote: If you need more help, I would gladly send you the output of `man vi' from a non-GNU Unix. I can also send you the output of `man vim' from a GNU system. It'll probably be easier to convince Guido to introduce a 'goto' statement than it would be to learn vi. I'm really not sure if I'm joking or not. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Christos TZOTZIOY Georgiou wrote: On Wed, 20 Apr 2005 16:13:32 +0300, rumours say that Maxim Kasimov [EMAIL PROTECTED] might have written: but what if i just can't to do this becouse i'm working thrue ssh, and have to use only installed editors (such as vi) If you use plain vi (not vim) and you want to comment e.g. 5 lines of code, go to the first of these five and: - if autoindent type: 5O^Dif 0:{ESC} ^D above is Ctrl-D, {ESC} is your Escape key - if noautoindent type: YP^Cif 0:{ESC}j5 ^C above is literal ^, literal C, *NOT* Ctrl-C; {ESC} is your Escape key To control autoindent, you can type: :se ai or :se noai If you need more help, I would gladly send you the output of `man vi' from a non-GNU Unix. I can also send you the output of `man vim' from a GNU system. is it wrong to debug python script using python, but not some magic commands found somewhere in man ? -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
by the way, goto statement will be useful for writing more powerful obfuscators -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Maxim Kasimov wrote: f..., i don't requesting that goto was available in next versions of python, but i'm saying if it will be so, it will be easy and quickly _debug_ some skripts, _not only_ for commenting Then we go right back to Simon Brunning's question for you: How does goto help you to remove bugs? Maxim, nobody is really saying that *you* cannot have found goto useful in debugging (though we're curious for a real example, rather than just rhetoric). What most people are saying (roughly) is that after writing tens (or hundreds) of thousands of lines of code, we cannot think of examples where the value of goto, for debugging or otherwise, outweighs the incredible damage it does to the structure and (thus) readability of code. And keep in mind that many of us were raised on languages like BASIC and yet we've learned, improved, and moved on to the point where we fully understand the perceived value of GOTO in the mind of a newbie, but remain unconvinced that even (or especially!) for a newbie it is a good idea to have it available. So far, nobody on the use goto! side of the fence has presented arguments that haven't already been shot down dozens of times in this newsgroup and elsewhere. Of course, we should all take this hint as a reminder that this is a religious issue and that this particular thread is not going to settle it once and for all. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
praba kar wrote: In Python what is equivalent to goto statement The group has been remiss, starting mainly with Mage's unfortunately dogmatic response. What we meant to ask was this: why do you want it? There are better, simpler, cleaner, more readable ways to accomplish what you are trying to do, if you'll only tell us what that is so we can show you. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On Wed, 20 Apr 2005 18:38:40 +0300, rumours say that Maxim Kasimov [EMAIL PROTECTED] might have written: If you need more help, I would gladly send you the output of `man vi' from a non-GNU Unix. I can also send you the output of `man vim' from a GNU system. is it wrong to debug python script using python, but not some magic commands found somewhere in man ? If you really believe you should use python to debug (and edit perhaps?) python, use idle and X11 forwarding through your ssh connection instead of vi. Then you have menu-driven block un/commenting and un/indenting. Otherwise, I believe your reply above is slightly adrift (you wondered what one can do to comment a block of code when using vi, and I replied to that; I don't quite understand what your exact point is.) -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On Wed, 20 Apr 2005 18:47:37 +0300, rumours say that Maxim Kasimov [EMAIL PROTECTED] might have written: by the way, goto statement will be useful for writing more powerful obfuscators At this point in time you might want to reconsider what are the true reasons you like python (if you really do :) -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Troll? was: Re: goto statement
Maxim Kasimov wrote: by the way, goto statement will be useful for writing more powerful obfuscators Let me get that clear: you want a goto to help with debugging. And you want to obfuscate your code even more? !? Perhaps you need to write in Perl, or some other similar language. Writing in Python is for those that seek clarity (not obfuscation) and less bugs. Which is why a goto statement should definitely never be part of Python! André -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On Wed, 20 Apr 2005 16:24:19 +0100, rumours say that Simon Brunning [EMAIL PROTECTED] might have written: On 4/20/05, Christos TZOTZIOY Georgiou [EMAIL PROTECTED] wrote: If you need more help, I would gladly send you the output of `man vi' from a non-GNU Unix. I can also send you the output of `man vim' from a GNU system. [Simon] It'll probably be easier to convince Guido to introduce a 'goto' statement than it would be to learn vi. I just happened to learn vi first before emacs, and this precedence set my preference. The only needed skill is to remember if you're in 'insert' or 'command' mode (or so I believe)... I'm really not sure if I'm joking or not. Have you ever heard of anyone *joking* about their preferred or hated text editor?-) -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
I do not want to pollute the debate but: -) I remember a software QA managanager responsible for C coding rules also not allowing us to use 'break', 'continue', or 'return' (in the middle of a function). Although I find them 'cleaner' than goto, would not use goto, and certainly do use 'return' in the middle of functions, I also agree that some people might think the former do reduce code readibility - ex: I , somehow, do not feel good using 'continue' and 'break'. -) Having worked on a few lex/yacc projects, I remmember being troubled ,as I ported the resulting c code into an embedded environement, that the latter extensively used gotos - Was that done only because people are not supposed to look at the generated code - or is it also simpler to generate non-structured C code ? Regards, Philippe Peter Hansen wrote: Maxim Kasimov wrote: f..., i don't requesting that goto was available in next versions of python, but i'm saying if it will be so, it will be easy and quickly _debug_ some skripts, _not only_ for commenting Then we go right back to Simon Brunning's question for you: How does goto help you to remove bugs? Maxim, nobody is really saying that *you* cannot have found goto useful in debugging (though we're curious for a real example, rather than just rhetoric). What most people are saying (roughly) is that after writing tens (or hundreds) of thousands of lines of code, we cannot think of examples where the value of goto, for debugging or otherwise, outweighs the incredible damage it does to the structure and (thus) readability of code. And keep in mind that many of us were raised on languages like BASIC and yet we've learned, improved, and moved on to the point where we fully understand the perceived value of GOTO in the mind of a newbie, but remain unconvinced that even (or especially!) for a newbie it is a good idea to have it available. So far, nobody on the use goto! side of the fence has presented arguments that haven't already been shot down dozens of times in this newsgroup and elsewhere. Of course, we should all take this hint as a reminder that this is a religious issue and that this particular thread is not going to settle it once and for all. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On 2005-04-20, Philippe C. Martin [EMAIL PROTECTED] wrote: Although I find them 'cleaner' than goto, would not use goto, and certainly do use 'return' in the middle of functions, I also agree that some people might think the former do reduce code readibility - ex: I , somehow, do not feel good using 'continue' and 'break'. Do you just avoid switch() statements? Or are you referring only to loop bodies? -- Grant Edwards grante Yow! LOOK!!! I'm WALKING at in my SLEEP again!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Loop bodies (for break) Grant Edwards wrote: On 2005-04-20, Philippe C. Martin [EMAIL PROTECTED] wrote: Although I find them 'cleaner' than goto, would not use goto, and certainly do use 'return' in the middle of functions, I also agree that some people might think the former do reduce code readibility - ex: I , somehow, do not feel good using 'continue' and 'break'. Do you just avoid switch() statements? Or are you referring only to loop bodies? -- http://mail.python.org/mailman/listinfo/python-list
Re: Troll? was: Re: goto statement
André Roberge wrote: Maxim Kasimov wrote: by the way, goto statement will be useful for writing more powerful obfuscators Let me get that clear: you want a goto to help with debugging. And you want to obfuscate your code even more? !? Perhaps you need to write in Perl, or some other similar language. Writing in Python is for those that seek clarity (not obfuscation) and less bugs. Which is why a goto statement should definitely never be part of Python! André so insulting to me - you asking i'm a troll, only becose i'm saing that goto maybe sometimes usefull. -- Best regards, Maxim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Troll? was: Re: goto statement
Maxim Kasimov wrote: André Roberge wrote: Maxim Kasimov wrote: by the way, goto statement will be useful for writing more powerful obfuscators Let me get that clear: you want a goto to help with debugging. And you want to obfuscate your code even more? !? Perhaps you need to write in Perl, or some other similar language. Writing in Python is for those that seek clarity (not obfuscation) and less bugs. Which is why a goto statement should definitely never be part of Python! André so insulting to me - you asking i'm a troll, only becose i'm saing that goto maybe sometimes usefull. No, because you said that it was useful for obfuscating code. Obfuscating code is generally not a desirable feature of a language construct. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Troll? was: Re: goto statement
On 4/20/05, Robert Kern [EMAIL PROTECTED] wrote: Maxim Kasimov wrote: André Roberge wrote: Maxim Kasimov wrote: by the way, goto statement will be useful for writing more powerful obfuscators Let me get that clear: you want a goto to help with debugging. And you want to obfuscate your code even more? !? Perhaps you need to write in Perl, or some other similar language. Writing in Python is for those that seek clarity (not obfuscation) and less bugs. Which is why a goto statement should definitely never be part of Python! André so insulting to me - you asking i'm a troll, only becose i'm saing that goto maybe sometimes usefull. No, because you said that it was useful for obfuscating code. Obfuscating code is generally not a desirable feature of a language construct. I believe he meant obfuscating bytecode for a commercial product, to try and avoid decompilation, which is often a desirable function for commercial entities. (Not that I have the technical knowledge to agree or disagree with what he said, I'm just trying to help clear up what's become a fairly bogged-down argument.) Peace Bill Mill bill.mill at gmail.com -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Philippe C. Martin wrote: I do not want to pollute the debate but: -) I remember a software QA managanager responsible for C coding rules also not allowing us to use 'break', 'continue', or 'return' (in the middle of a function). And I once worked (back in the 1970's) in a software shop where because procedure calls are slow in PL/1 we had to write them so each procedure ended with a GOTO to a specific label variable. You would call these monstrosities in the following way: MyProcReturn = DoneIt; GOTO MyProc; DoneIt: ... Horrendous. I lasted about five months and then couldn't take the ignorance and idiocy any longer. They refused to believe that a recursive function could ever be useful in the real world (but then, if you only have a hammer ...) regards Steve -- Steve Holden+1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
I guess the point could be where do you draw the line: you can break and continue in Python, but you cannot goto. Some people, so it seems ;-) , would like to see gotos in Python whereas other think breaks and continues should be excluded ...; Regards, Philippe Steve Holden wrote: Philippe C. Martin wrote: I do not want to pollute the debate but: -) I remember a software QA managanager responsible for C coding rules also not allowing us to use 'break', 'continue', or 'return' (in the middle of a function). And I once worked (back in the 1970's) in a software shop where because procedure calls are slow in PL/1 we had to write them so each procedure ended with a GOTO to a specific label variable. You would call these monstrosities in the following way: MyProcReturn = DoneIt; GOTO MyProc; DoneIt: ... Horrendous. I lasted about five months and then couldn't take the ignorance and idiocy any longer. They refused to believe that a recursive function could ever be useful in the real world (but then, if you only have a hammer ...) regards Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Troll? was: Re: goto statement
Bill Mill wrote: I believe he meant obfuscating bytecode for a commercial product, to try and avoid decompilation, which is often a desirable function for commercial entities. there is no shortage of jump instructions on the bytecode level, so if he wants to obfuscate bytecode, all he has to do is to obfuscate the bytecode. import dis [op for op in dis.opname if op.startswith(JUMP)] ['JUMP_FORWARD', 'JUMP_IF_FALSE', 'JUMP_IF_TRUE', 'JUMP_ABSOLUTE'] /F -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
On Wed, 20 Apr 2005 10:23:58 +0100 (BST), praba kar [EMAIL PROTECTED] wrote: Dear All, In Python what is equivalent to goto statement I'd like to that implemented in an interpreted language. Requires some time travel. Matt Feinstein -- There is no virtue in believing something that can be proved to be true. -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
Matt Feinstein wrote: On Wed, 20 Apr 2005 10:23:58 +0100 (BST), praba kar [EMAIL PROTECTED] wrote: Dear All, In Python what is equivalent to goto statement I'd like to that implemented in an interpreted language. Requires some time travel. Yes, to 2004-04-01. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
In article [EMAIL PROTECTED], Maxim Kasimov [EMAIL PROTECTED] wrote: Simon Brunning wrote: On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote: it would be quite useful for debuging porposes How does goto help you to remove bugs? I can certainly see how it helps you put them in in the first place... if you need to comment a couple of code (and then uncomment ), what are you doing then? . . . I might understand the question. I often have if 0: # This is code we never should need; I # leave it here for expository purposes. print some_key_debugging_information() Does that help? -- http://mail.python.org/mailman/listinfo/python-list
Re: goto statement
In article [EMAIL PROTECTED], Maxim Kasimov [EMAIL PROTECTED] wrote: . . . if you need to comment a couple of code (and then uncomment ), what are you doing then? Use comments? WOW, just greate! ... but i'd like to relax at some more interesting way than to comment each of rows . . . Mr. Kasimov, here's another idiom you might want to consider: # Notice that we can make a code fragment into a string, # which is evaluated, then discarded. a = b c = d e = f g = h i = j k = l -- http://mail.python.org/mailman/listinfo/python-list
Re: Troll? was: Re: goto statement
Maxim Kasimov wrote: André Roberge wrote: Maxim Kasimov wrote: by the way, goto statement will be useful for writing more powerful obfuscators Let me get that clear: you want a goto to help with debugging. And you want to obfuscate your code even more? !? Perhaps you need to write in Perl, or some other similar language. Writing in Python is for those that seek clarity (not obfuscation) and less bugs. Which is why a goto statement should definitely never be part of Python! André so insulting to me - you asking i'm a troll, only becose i'm saing that goto maybe sometimes usefull. Seemed like a fair response to me, given that computer scientists and programming practitioners concluded years ago that the potential of goto constructs was largely negative, and that they should be eschewed under most normal circumstances. This has now been carried to the extent that there are may other languages besides Python that don't include a GOTO. Do you know something we (and they) don't? If not then this is just an idle conversation, since you don't appear to perceive the negative aspects at all. regards Steve -- Steve Holden+1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: GOTO (was Re: Appeal for python developers)
On Sunday 06 March 2005 14:26, Anthra Norell wrote: snip long goto explanation Wow, I never thought I'd say this, but this certainly is an ingenious use of goto... But, nevertheless, I don't think this is applicable to Python as a way of justifying goto in the language, as your program doesn't have a split between abstract state machine and real program anymore (which I think should be there, as the abstract state machine is actually data, which controls program flow). The way I'd code it in Python is something like: SETUP = object() ELSE = object() BREAK = object() machine = {WAITING FOR ACTION: {customer_drops_coin:COIN HAS BEEN DROPPED, customer_selects_beverage:ORDER RECEIVED, customer_cancels_order:ACCOUNT CLOSURE IS DUE ELSE:WAITING FOR ACTION}, COIN HAS BEEN DROPPED: {SETUP:identify_coin, credit_account:PAYMENT DUE IS UNKNOWN}, ORDER RECEIVED: {... Reading the state machine in the way presented above isn't any harder in my taste than reading your state table, and you should easily be able to run the machine from there... -- --- Heiko. pgpFSqfb8wW7l.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: GOTO (was Re: Appeal for python developers)
Heiko wrote: SETUP = object() ELSE = object() BREAK = object() machine = {"WAITING FOR ACTION": {customer_drops_coin:"COIN HAS BEEN DROPPED", customer_selects_beverage:"ORDER RECEIVED", customer_cancels_order:"ACCOUNT CLOSURE IS DUE" ELSE:"WAITING FOR ACTION"}, "COIN HAS BEEN DROPPED": {SETUP:identify_coin, credit_account:"PAYMENT DUE IS UNKNOWN"}, "ORDER RECEIVED": {... Reading the state machine in the way presented above isn't any harder in my taste than reading your state table, and you should easily be able to run the machine from there... --- Heiko. I think I get your idea. I also see a few problems with your proposal. Let me try: def customer_drops_coin (): ... def customer_selects_beverage (): ... def customer_cancels_order: ... etc. def ELSE:return True machine = { "WAITING FOR ACTION": ( ( customer_drops_coin, "COIN HAS BEEN DROPPED" ), ( customer_selects_beverage, "ORDER RECEIVED" ), ( customer_cancels_order, "ACCOUNT CLOSURE IS DUE" ), #( ELSE, "WAITING FOR ACTION" ), ), "COIN HAS BEEN DROPPED": ( ( identify_coin,None), ( credit_account, "PAYMENT DUE IS UNKNOWN" ), ), "ORDER RECEIVED": ( (... def run_state_machine (machine, initial_state = "BEGIN"): state = initial_state # Here would be "WAITING FOR ACTION" while True: forfunction, next_statein machine [state]: go_next = function () if go_next: if next_state: state = next_state if state == "END": return This should work. Frederic -- http://mail.python.org/mailman/listinfo/python-list
Re: GOTO (was Re: Appeal for python developers)
Please include "goto" command in future python realeses know that proffesional programers doesn't like to use it, but for me as newbie it's too hard to get used replacing it with "while", "def" or other commands -- I believe the bad reputation of 'goto' goes back to the originators of structured programming and what they meant to say was: don't use goto as a quick fix for a poorly written tangle of looping constructs. It aggravates the tangle when the solution is to straighten it out. Had they deemed 'goto' useless, they would have thrown it out there and then. They didn't, because a policy against misuse that prevents all use runs against the interests of those capable of avoiding the misuse on their own. Typically, elites revolt against dictatorial restrictions. Here, strangely, the elites afflict themselves voluntarily with a sort of gotophobia as a hallmark of professionalism. I had a period when I was into state machines and came up with a programming technique that started out with a state table in three columns. This example is a vending machine. Current state Transition event(s) Next state(s) WAITING FOR ACTION customer drops coin COIN HAS BEEN DROPPED customer selects beverage ORDER RECEIVED customer cancels order ACCOUNT CLOSURE IS DUE else WAITING FOR ACTION COIN HAS BEEN DROPPED identify coincredit account PAYMENT DUE IS UNKNOWN ORDER RECEIVED display selection PAYMENT DUE IS UNKNOWN PAYMENT DUE IS UNKNOWN no selection made NOTHING IS ORDERED payment is short PAYMENT IS SHORT else PAYMENT COVERS NOTHING IS ORDERED prompt for selection WAITING FOR ACTION PAYMENT IS SHORT display balance due prompt for payment WAITING FOR ACTION PAYMENT COVERS prompt for release action WAITING FOR RELEASE ACTION WAITING FOR RELEASE ACTION customer activates release DELIVERY IS DUE customer drops coin COIN HAS BEEN DROPPED customer selects beverage ORDER_RECEIVED customer cancels orderACCOUNT CLOSURE IS DUE else WAITING FOR RELEASE ACTION DELIVERY IS DUE release beverage debit account ACCOUNT CLOSURE IS DUE ACCOUNT CLOSURE IS DUE return account balance WAITING FOR ACTION All of the next states reappear, no more than once each, in the first column as current states and so the table is consistent and exhaustive. Consistency is automatic regardless how big a table grows, if every new next state entered is copied right away into the first column where a bunch of them may accumulate, each one conspicuously unhandled as long as it stands alone on its line. Their order is irrelevant. Converting the table into a program is trivial, because the table is a program. A few minor formal edits make it digestible for a C compiler: WAITING_FOR_ACTION: if customer_drops_coin () goto COIN_HAS_BEEN_DROPPED; if customer_selects_beverage () goto ORDER_RECEIVED; if customer_cancels_order () goto ACCOUNT_CLOSURE_IS_DUE; goto WAITING_FOR_ACTION; COIN_HAS_BEEN_DROPPED: identify_coin (); credit_account (); goto PAYMENT_DUE_IS_UNKNOWN; ORDER_RECEIVED: display_selection ();goto PAYMENT_DUE_IS_UNKNOWN; PAYMENT_DUE_IS_UNKNOWN: if no_selection_made () goto NOTHING_IS_ORDERED; if payment_is_short () goto PAYMENT_IS_SHORT; goto PAYMENT_COVERS; NOTHING_IS_ORDERED: prompt_for_selection ();goto WAITING_FOR_ACTION; PAYMENT_IS_SHORT: display_balance_due (); prompt_for_balance_due ();goto WAITING_FOR_ACTION; PAYMENT_COVERS: prompt_for_release_action ();// goto WAITING_FOR_RELEASE_ACTION; WAITING_FOR_RELEASE_ACTION: if customer_activates_release () goto DELIVERY_IS_DUE; if customer_drops_coin () goto COIN_HAS_BEEN_DROPPED; if customer_selects_beverage () goto ORDER_RECEIVED; if customer_cancels_order () goto ACCOUNT_CLOSURE_IS_DUE; goto WAITING_FOR_RELEASE_ACTION; DELIVERY_IS_DUE: release_beverage (); debit_account (); // goto ACCOUNT_CLOSURE_IS_DUE; ACCOUNT_CLOSURE_IS_DUE: return_account_balance ();goto WAITING_FOR_ACTION; An anachronism? So what? Isn't it simple, elegant, legible, easy to modify and expand and self-documenting on top of it?One advantage of this method is that legibility does not degrade as the complexitiy of the transition paths increases. Conditional loops do become increasingly difficult to follow as they nest and accumulate breaks and state flags, and somodifications become increasingly difficult to make. An upgrade simpler than the following one, on the other hand, is hard to imagine: COIN_HAS_BEEN_DROPPED: identify_coin (); if coin_is_a_dud () goto HOLDING_UNWANTED_PROPERTY; // Newcredit_account (); goto PAYMENT_DUE_IS_UNKNOWN; HOLDING_UNWANTED_PROPERTY: reject_dud (); // New /* admonish_customer (); */ goto WAITING_FOR_ACTION; // New I used this technique in C and found it useful on some occasions. I did not combine gotos and loops.Not all problems lend themselves to this solution,
Re: GOTO (was Re: Appeal for python developers)
Paul McGuire wrote: At the risk of beating this into the Pythonic ground, here is a generator version which collapses the original nested loop into a single loop, so that break works just fine: Indeed. For some things I'm still in the pre-generator days of Python. If I worked at it I think I could come up with an example that wouldn't be so easy to turn into an iterator, but that would be not only be beating it into the ground but doing a clog dance on top. Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: GOTO (was Re: Appeal for python developers)
At the risk of beating this into the Pythonic ground, here is a generator version which collapses the original nested loop into a single loop, so that break works just fine: .def getCombinations(*args): .if len(args) 1: .for a0 in args[0]: .for remainder in getCombinations(*args[1:]): .yield [a0]+remainder .else: .for a0 in args[0]: .yield [a0] . .for i,j,k in getCombinations(xrange,yrange,zrange): .if lookup(i,j,k) == target: .print Eureka! .break .else: .print Rats! No match found. Now that we have getCombinations in our toolkit, we can also do things like: .numbers = range(2) .colors = ['red','green','blue','orange','white'] .sizes = ['S','M','L','XL','XXL'] .letters = ABCDE .print [ c for c in getCombinations(numbers, colors) ] .print [ c for c in getCombinations(numbers, colors, sizes) ] .print [ c for c in getCombinations(letters,colors) ] .print [ c for c in getCombinations(letters,letters) ] # take letters two at a time .print [ .join(c) for c in getCombinations(letters,letters) ] giving: [[0, 'red'], [0, 'green'], [0, 'blue'], [0, 'orange'], [0, 'white'], [1, 'red'], [1, 'green'], [1, 'blue'], [1, 'orange'], [1, 'white']] [[0, 'red', 'S'], [0, 'red', 'M'], [0, 'red', 'L'], [0, 'red', 'XL'], [0, 'red', 'XXL'], [0, 'green', 'S'], [0, 'green', 'M'], [0, 'green', 'L'], [0, 'green', 'XL'], [0, 'green', 'XXL'], [0, 'blue', 'S'], [0, 'blue', 'M'], [0, 'blue', 'L'], [0, 'blue', 'XL'], [0, 'blue', 'XXL'], [0, 'orange', 'S'], [0, 'orange', 'M'], [0, 'orange', 'L'], [0, 'orange', 'XL'], [0, 'orange', 'XXL'], [0, 'white', 'S'], [0, 'white', 'M'], [0, 'white', 'L'], [0, 'white', 'XL'], [0, 'white', 'XXL'], [1, 'red', 'S'], [1, 'red', 'M'], [1, 'red', 'L'], [1, 'red', 'XL'], [1, 'red', 'XXL'], [1, 'green', 'S'], [1, 'green', 'M'], [1, 'green', 'L'], [1, 'green', 'XL'], [1, 'green', 'XXL'], [1, 'blue', 'S'], [1, 'blue', 'M'], [1, 'blue', 'L'], [1, 'blue', 'XL'], [1, 'blue', 'XXL'], [1, 'orange', 'S'], [1, 'orange', 'M'], [1, 'orange', 'L'], [1, 'orange', 'XL'], [1, 'orange', 'XXL'], [1, 'white', 'S'], [1, 'white', 'M'], [1, 'white', 'L'], [1, 'white', 'XL'], [1, 'white', 'XXL']] [['A', 'red'], ['A', 'green'], ['A', 'blue'], ['A', 'orange'], ['A', 'white'], ['B', 'red'], ['B', 'green'], ['B', 'blue'], ['B', 'orange'], ['B', 'white'], ['C', 'red'], ['C', 'green'], ['C', 'blue'], ['C', 'orange'], ['C', 'white']] [['A', 'A'], ['A', 'B'], ['A', 'C'], ['B', 'A'], ['B', 'B'], ['B', 'C'], ['C', 'A'], ['C', 'B'], ['C', 'C']] ['AA', 'AB', 'AC', 'BA', 'BB', 'BC', 'CA', 'CB', 'CC'] Finally, these last two examples make me think of permutations as well (in which order is significant - can't count both AB and BA). So here is a brute force version of getPermutations, built on getCombinations, but filtering previously reported duplicates: .from sets import Set as set .def getPermutations(*args): .prevs = [] .for comb in getCombinations(*args): .thisComb = set(comb) .if not thisComb in prevs: .prevs.append(thisComb) .yield comb . .print [ c for c in getPermutations(letters,letters) ] .print [ .join(c) for c in getPermutations(letters,letters) ] gives: [['A', 'A'], ['A', 'B'], ['A', 'C'], ['B', 'B'], ['B', 'C'], ['C', 'C']] ['AA', 'AB', 'AC', 'BB', 'BC', 'CC'] -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: GOTO (was Re: Appeal for python developers)
[EMAIL PROTECTED] wrote: Goto is useful [...] when there is a clean-up section of a function that should be executed for various error conditions. Like this? def foo(): f = open('foo.txt') try: # do stuff with f finally: f.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: GOTO (was Re: Appeal for python developers)
Dennis Lee Bieber wrote: On 5 Mar 2005 08:00:23 -0800, [EMAIL PROTECTED] declaimed the following in comp.lang.python: explicit GOTO'. Goto's are less dangerous when they are in the forward direction, to code appearing later. UGH... That is the one direction I always avoid (in FORTRAN 77). Typical example of forward GOTOs in Python source: static PyObject * min_max(PyObject *args, PyObject *kwds, int op) { ... while (( item = PyIter_Next(it) )) { /* get the value from the key function */ if (keyfunc != NULL) { val = PyObject_CallFunctionObjArgs( keyfunc, item, NULL); if (val == NULL) goto Fail_it_item; } ... else { int cmp = PyObject_RichCompareBool( val, maxval, op); if (cmp 0) goto Fail_it_item_and_val; else if (cmp 0) { ... } } } if (PyErr_Occurred()) goto Fail_it; ... return maxitem; Fail_it_item_and_val: Py_DECREF(val); Fail_it_item: Py_DECREF(item); Fail_it: Py_XDECREF(maxval); Py_XDECREF(maxitem); Py_DECREF(it); return NULL; } Note that the GOTOs are basically there to take care of the appropriate decref-ing if exceptions occur. STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Erik Bethke wrote: At least I thought this was funny and cool! -Erik Thanks. ;) -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Mike Meyer wrote: Secondly, how do I clear screen (cls) from text and other content ? That depends on A: What type of display device you're using B: What type of interface is being rendered on that display (command line, GUI, IDE, etc) C: Perhaps what operating system you are using. D: Whether or not you have a display device at all. I run Python scripts from Cron whose sole output functionality is via email. I run Python scripts as daemons whose sole output functionality is syslog. are you the original poster? if so, can you explain why you asked how to clear the screen if you don't have a screen? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
You sir are a troll for sure. QBasic?! When was the last time you did any programming, 1989? Gave me a laugh though. Lars -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
jean-michel [EMAIL PROTECTED] wrote: And it was not possible to remove GOTO, because that would really need to rewrite manually the programs really? converting GOTO messes to structured programs has been a solved problem for many years (you can buy commercial products that does this, and I don't think they come with programmers in the box) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Alan Kennedy [EMAIL PROTECTED] writes: Secondly, how do I clear screen (cls) from text and other content ? That depends on A: What type of display device you're using B: What type of interface is being rendered on that display (command line, GUI, IDE, etc) C: Perhaps what operating system you are using. D: Whether or not you have a display device at all. I run Python scripts from Cron whose sole output functionality is via email. I run Python scripts as daemons whose sole output functionality is syslog. Clear screen doesn't make sense in thsoe two contexts. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Harlin wrote: No goto needed. If this makes no sense (which it may not if all you've been exposed to is BASIC) it wouldn't be a bad idea to Google why you should never use a goto statement. GOTO isn't even needed in QBasic (except for ON ERROR GOTO). -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN [EMAIL PROTECTED] a écrit dans le message de news:[EMAIL PROTECTED] I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? Secondly, how do I clear screen (cls) from text and other content ? And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. Hi all, I saw a lot of comments saying GOTO is not usefull, very bad, and we should'nt use it because we don't need it. I think that's true, but only if you *create* programs. But if the goal is to provide some kind of converter to automatically take an old application written with an old language (using GOTO), and generating python code, it would certainly a great help to have this (unclean) feature in native python. Best regards jm -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Grant Edwards [EMAIL PROTECTED] wrote: I forgot to mention try/except. When I do use goto in C programming it's almost always to impliment what would have been a try/except block in Python. Yes I'd agree with that. No more 'goto out'. There is this also for (i = 0; ...) { if (something) goto found; } /* do stuff when not found */ found:; (yes I hate setting flags in loops ;-) This translates exactly to the for: else: construct for i in xrange(...): if something: break else: # do stuff when not found The last language I saw with this very useful feature was FORTH in about 1984! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
jean-michel wrote: Hi all, I saw a lot of comments saying GOTO is not usefull, very bad, and we should'nt use it because we don't need it. I think that's true, but only if you *create* programs. But if the goal is to provide some kind of converter to automatically take an old application written with an old language (using GOTO), and generating python code, it would certainly a great help to have this (unclean) feature in native python. But an automatic translator is certain to be imperfect. One can no more translate mechanically between computer languages than one can translate mechanically between human languages -- and we've all seen the fun that can be had by machine-translating from language A - language B - language A, right? What do you think the effect of that sort of meaning-drift would be on application code? In other words, any translation from one language to another will require significant human attention, by someone familiar with both languages, to ensure that the original meaning is preserved as close as possible. You're going to have to rewrite chunks of code by hand no matter what you do; it'd be silly to *not* take that opportunity to purge things like GOTO. Jeff Shannon Technician/Programmer Credit International -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN a écrit : I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? I had a professor that told me that using goto in prog is that there is a mistake in the algorythm. If I remember, I think there is no goto instruction in python ! Secondly, how do I clear screen (cls) from text and other content ? I don't understand well what you exactly want to do. Can you explain more please. And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. import time time.sleep(10) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN wrote: I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? There isn't one. Why do you think you need this? Secondly, how do I clear screen (cls) from text and other content ? That depends on your computer, and how you are running your program. One way which *might* work is: import os os.system(cls) And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. import time time.sleep(10) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
On Thu, 10 Feb 2005 16:59:04 +0100, rumours say that BOOGIEMAN [EMAIL PROTECTED] might have written: Best advice: try to forget QBasic, and try again reading the tutorial. That, if your post is serious. If it isn't, keep reading my reply :) I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? goto for python: http://entrian.com/goto/index.html Please ignore the line in bold red. Secondly, how do I clear screen (cls) from text and other content ? Python clears after itself, so you don't need to. If you insist though, . import os . os.system('cls') That on a windows console. If on IDLE, try closing the window and reopening it. And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. (A serious answer for a change) Waiting is time related. So import time and call the time.sleep function. Try entering help at a Python prompt. -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
On 2005-02-10, BOOGIEMAN [EMAIL PROTECTED] wrote: First of all, what's Python command equivalent to QBasic's goto ? There isn't one. One defines functions and calls them. One uses for and while loops. One uses list comprehensions. One uses if/elif/else. Secondly, how do I clear screen (cls) from text and other content ? That depends on the host system. Under Unix, you can do os.system('clear'). Or you can use ncurses. Or you can use os.system to run the 'tput' command with appropriate parameters -- see the tput man page. There's probably some way to do it in Windows as well, but I don't do windows. And last, how do I put program to wait certain amount of seconds ? time.sleep(1) will wait for 1 second. time.sleep(5.5) will wait for 5.5 seconds. -- Grant Edwards grante Yow! Yow! I like my new at DENTIST... visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
[BOOGIEMAN] I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? Oh no! You said the G word! That's a dirty word in computer science circles, because of the perception that goto (there, I said it, ugh!) can lead people to structure their code badly, i.e. write bad programs. Instead, most modern programming languages offer a range of control and looping constructs that allow you to code your intention more clearly than with goto. Python examples include while, for .. in .., try .. except .., etc, etc. So in order to answer your question, you're probably going to have to be more specific on what you want goto for. Interestingly, gotos are undergoing a bit of renaissance in coding circles, but people have felt compelled to call them something different: continuations. But you're probably not interested in them. And python can't do them anyway. Secondly, how do I clear screen (cls) from text and other content ? That depends on A: What type of display device you're using B: What type of interface is being rendered on that display (command line, GUI, IDE, etc) C: Perhaps what operating system you are using. And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. Ahh, a simple question! :-) import time time.sleep(10.0) HTH, -- alan kennedy -- email alan: http://xhaus.com/contact/alan -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Duncan Booth a écrit : BOOGIEMAN wrote: (snip) Secondly, how do I clear screen (cls) from text and other content ? That depends on your computer, and how you are running your program. One way which *might* work is: import os os.system(cls) *might* work... !-) [EMAIL PROTECTED] modulix $ cls -bash: cls: command not found Bad luck ! didn't work !-) Bruno -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Grant Edwards a écrit : On 2005-02-10, BOOGIEMAN [EMAIL PROTECTED] wrote: First of all, what's Python command equivalent to QBasic's goto ? There isn't one. One defines functions and calls them. One uses for and while loops. One uses list comprehensions. One uses if/elif/else. and even sometimes break, continue, and return !-) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
On 2005-02-10, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Grant Edwards a écrit : On 2005-02-10, BOOGIEMAN [EMAIL PROTECTED] wrote: First of all, what's Python command equivalent to QBasic's goto ? There isn't one. One defines functions and calls them. One uses for and while loops. One uses list comprehensions. One uses if/elif/else. and even sometimes break, continue, and return !-) I forgot to mention try/except. When I do use goto in C programming it's almost always to impliment what would have been a try/except block in Python. -- Grant Edwards grante Yow! ... the MYSTERIANS at are in here with my visi.comCORDUROY SOAP DISH!! -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Bruno Desthuilliers wrote: Duncan Booth a écrit : BOOGIEMAN wrote: Secondly, how do I clear screen (cls) from text and other content ? That depends on your computer, and how you are running your program. One way which *might* work is: import os os.system(cls) *might* work... !-) [EMAIL PROTECTED] modulix $ cls -bash: cls: command not found Bad luck ! didn't work !-) Works for me! But then again... kairos:ug cat cls #! /usr/local/bin/python print \xc, /ug 8-) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
import os if os.name == nt: os.system(cls) # Works in w2k else: os.system(clear)# Works in cygwin's Bash Ulf Göransson wrote: Bruno Desthuilliers wrote: Duncan Booth a écrit : BOOGIEMAN wrote: Secondly, how do I clear screen (cls) from text and other content ? That depends on your computer, and how you are running your program. One way which *might* work is: import os os.system(cls) *might* work... !-) [EMAIL PROTECTED] modulix $ cls -bash: cls: command not found Bad luck ! didn't work !-) Works for me! But then again... kairos:ug cat cls #! /usr/local/bin/python print \xc, /ug 8-) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
OK, thanks all Here's presentation of my advanced programming skills :) import os import time os.system(cls) number = 78 guess = 0 while guess != number: guess = input(Guess number: ) if guess number: print Lower time.sleep(3) os.system(cls) elif guess number: print Higher time.sleep(3) os.system(cls) print That's the number ! --- BTW, I'm thinking to replace lines time.sleep(3) with something like Press any key to guess again How do I do that ? Also I wanted to put at the end something like Do you want to guess again ? and then GOTO start of program, but since there is no such command in Python what are my possible solutions ? -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN said unto the world upon 2005-02-10 16:06: OK, thanks all Here's presentation of my advanced programming skills :) import os import time os.system(cls) number = 78 guess = 0 while guess != number: guess = input(Guess number: ) if guess number: print Lower time.sleep(3) os.system(cls) elif guess number: print Higher time.sleep(3) os.system(cls) print That's the number ! --- BTW, I'm thinking to replace lines time.sleep(3) with something like Press any key to guess again How do I do that ? Also I wanted to put at the end something like Do you want to guess again ? and then GOTO start of program, but since there is no such command in Python what are my possible solutions ? Hi, I'm no expert and I owe much of whatever I know to the Python Tutor list. I'd suggest you check it out http://mail.python.org/mailman/listinfo/tutor. As for your situation, I'd do something like this untested code: guess = input(Guess number: ) while guess != number: print `Nope.' guess = raw_input('Guess again? (Enter q for quit)') if guess.lower() == 'q': # .lower() ensures 'Q' will match print `Quitter!' break if guess number: # stuff here if guess number: # different stuff here raw_input is safer than input as it prevents malicious code from ruining your day. A while loop is the usual way to repeat something until some condition is met. Here it repeats until guess == number. Another common idiom is while True: # do some stuff if some_condition: # some condition being True signals the break # need to break out of the loop I game to Python 10'ish years after I'd programmed some in BASIC and then not again. It took me a while to grok goto-less coding, too :-) HTH, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
No goto needed. If this makes no sense (which it may not if all you've been exposed to is BASIC) it wouldn't be a bad idea to Google why you should never use a goto statement. To do a clear screen you'll need to use the method that your command shell uses. The shortcut to this is for Windows, 'cls' and Linux (and other Unix derivatives) is 'clear'. To put this into your programs you'll need to import the OS module. Then use the method, system() to run the command: import os os.system('cls') or os.system('clear') To do a 'wait' you can use the Time module. import time seconds = 10 #This is an integer value time.sleep(seconds) Only on Unix systems can you use the system command 'sleep'. However, in the name of portability it's better to use the Python modules whenever possible (they'll work on any system that supports Python). Hope it helps. Harlin -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN wrote: First of all, what's Python command equivalent to QBasic's goto ? You can only use the goto function if you use Python with line numbers, thusly: 10 import sys 20 real_stdout = sys.stdout 30 class fake_stdout(object): pass 40 fake_stdout.write = lambda x, y: None 50 sys.stdout = fake_stdout() 60 import this 70 sys.stdout = real_stdout 80 d = {} 90 c = 65 100 i = 0 110 d[chr(i+c)] = chr((i+13) % 26 + c) 120 if i == 26: goto(150) 130 i += 1 140 goto(110) 150 if c == 97: goto(180) 160 c = 97 170 goto(100) 180 print How zen it is: 190 print .join([d.get(c, c) for c in this.s]) z = dict((int(x[0]), .join(x[1:])) for x in (y.split() for y in (__doc__ or _).strip().splitlines())); k = [0] + sorted(z.keys()); m = dict((b,a) for a,b in enumerate(k)); l = k[1] def goto(n): global l; l = k[m[n]-1] while l and l = k[-1]: exec z[l]; l = l != k[-1] and k[m[l]+1] -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
On Windows, I use WConio http://newcenturycomputers.net/projects/wconio.html It provides other screen functions you might have gotten used to in QBasic as well. On unix/cygwin, use curses. I am not aware of any portable library though. I used to use cls a lot in my QBasic days. Now I just don't. -- http://mail.python.org/mailman/listinfo/python-list