Re: [Tutor] a little loop

2013-05-28 Thread Jim Mooney
On 28 May 2013 22:33, Andreas Perstinger wrote: > Wow, that means I can do this: print ''.join('But this parrot is dead!') >> > > But why do you want to do that? > Actually, I meant to do this: print ''.join(' '.join('But this parrot is dead'.split())) Which has the same effect. There is a

Re: [Tutor] a little loop

2013-05-28 Thread Andreas Perstinger
On 29.05.2013 05:20, Jim Mooney wrote: On 28 May 2013 19:34, Steven D'Aprano wrote: The standard method for assembling a string from a collection of substrings is to do it in one go, using the join method, Wow, that means I can do this: print ''.join('But this parrot is dead!') But why

Re: [Tutor] a little loop

2013-05-28 Thread Jim Mooney
On 28 May 2013 19:34, Steven D'Aprano wrote: The standard method for assembling a string from a collection > of substrings is to do it in one go, using the join method, Wow, that means I can do this: print ''.join('But this parrot is dead!') -- Jim Ornhgvshy vf orggre guna htyl

Re: [Tutor] a little loop

2013-05-28 Thread Steven D'Aprano
On 28/05/13 13:54, Tim Hanson wrote: Okay, so I made it to FOR loops in the Lutz book. A couple of days ago I was helped here with the .join method for creating strings from lists or tuples of strings. I got to wondering if I could just, for the sake of learning, do the same thing in a FOR loop

Re: [Tutor] Socket Error Handling Syntax

2013-05-28 Thread eryksun
On Tue, May 28, 2013 at 3:49 PM, Dave Angel wrote: > I don't use Windows, but I doubt if there's a separate exception > type for 10057. Windows sockets error codes at or above 1 aren't mapped to POSIX error codes. Instead errno is set directly from winerror. So there's no reason to look at wi

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread Alan Gauld
On 28/05/13 21:15, Jim Mooney wrote: I think authors miss a didactic opportunity by not using bytecode as a teaching tool now and then, since it's easily explained, at least for basic statements. Assuming you mean the assembler statements then it may be true. Looking at Bytecode is just an exe

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread Jim Mooney
On 28 May 2013 04:18, Dave Angel wrote: > On 05/28/2013 07:02 AM, Jim Mooney wrote: > Alan and Devin already gave more specifics, but to repeat, > > import dis > > dis.dis(myfunction) > > will disassemble one function. I think authors miss a didactic opportunity by not using bytecode as a teachi

Re: [Tutor] Socket Error Handling Syntax

2013-05-28 Thread Andreas Perstinger
On 28.05.2013 21:37, sparkle Plenty wrote: If I use an if statement, I cannot use continue after I do my error handling, so I am really trying to use the except errorname: instead of an if statement. I think you haven't understood the code snippet I've posted. The if-statement is inside the ex

Re: [Tutor] Socket Error Handling Syntax

2013-05-28 Thread Dave Angel
On 05/28/2013 03:37 PM, sparkle Plenty wrote: If I use an if statement, I cannot use continue after I do my error handling, The presence of an if statement cannot affect whether or not a continue can work. If you give a concrete code example, somebody will be able to identify the confusion.

Re: [Tutor] Socket Error Handling Syntax

2013-05-28 Thread sparkle Plenty
If I use an if statement, I cannot use continue after I do my error handling, so I am really trying to use the except errorname: instead of an if statement. Therefore, I have to find the correct error name to identify the 10057 condition to the interpreter, but thanks anyway, Andreas. On Tue, Ma

Re: [Tutor] Socket Error Handling Syntax

2013-05-28 Thread Andreas Perstinger
On 28.05.2013 19:25, sparkle Plenty wrote: I need to catch and handle 10057 exceptions when they occur and keep running. I know 10057 is a WinError, which is a subset of OSError, I just can't find the right syntax for it. I would appreciate some help on this one. I have neither Windows nor Py

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread eryksun
On Tue, May 28, 2013 at 1:58 PM, Oscar Benjamin wrote: > > So what happens to the code object for the top-level code in the > module itself when it is imported in the normal way? Is it just > discarded once import is complete? Is it temporarily accessible during > import? Normally, nothing holds

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread Oscar Benjamin
On 28 May 2013 18:24, eryksun wrote: > On Tue, May 28, 2013 at 1:12 PM, Oscar Benjamin > wrote: >> On 28 May 2013 17:48, eryksun wrote: >>> >>> The argument for dis.dis() can be a module, class, function or code >>> object. It disassembles all the top-level code objects that it finds, >>> but it

Re: [Tutor] Python "well-formed formulas"

2013-05-28 Thread Dave Angel
On 05/28/2013 09:45 AM, Citizen Kant wrote: I'm trying to figure out the rules on how to recognize when a combination of symbols is considered a well formed expression in Python. Since I couldn't find any doc that lists all Python syntax rules --or maybe the doc is too long to be managed b

[Tutor] Socket Error Handling Syntax

2013-05-28 Thread sparkle Plenty
Python 3.3, Windows operating system: I am communicating with a device using a Python script and I am coding except clauses in my send and receive functions to handle a particular error. I can't find a WinError example, and I can't get the syntax right. I have researched this and tried the follow

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread eryksun
On Tue, May 28, 2013 at 1:12 PM, Oscar Benjamin wrote: > On 28 May 2013 17:48, eryksun wrote: >> >> The argument for dis.dis() can be a module, class, function or code >> object. It disassembles all the top-level code objects that it finds, >> but it doesn't recursively disassemble code objects t

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread Oscar Benjamin
On 28 May 2013 17:48, eryksun wrote: > On Tue, May 28, 2013 at 7:18 AM, Dave Angel wrote: >> >> dis.dis(myfunction) >> >> will disassemble one function. >> >> That's not all that's in the byte-code file, but this is 98% of what you >> probably want out of it. And you can do it in the debugger wi

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread eryksun
On Tue, May 28, 2013 at 7:18 AM, Dave Angel wrote: > > dis.dis(myfunction) > > will disassemble one function. > > That's not all that's in the byte-code file, but this is 98% of what you > probably want out of it. And you can do it in the debugger with just the > standard library. The argument f

Re: [Tutor] Python "well-formed formulas"

2013-05-28 Thread Walter Prins
Citizen, On 28 May 2013 14:45, Citizen Kant wrote: > I'm trying to figure out the rules on how to recognize when a combination > of symbols is considered a well formed expression in Python. > How do you recognize that an arithmetic expression is a well formed (e.g. valid) expression? How do

Re: [Tutor] Python "well-formed formulas"

2013-05-28 Thread Steven D'Aprano
On 28/05/13 23:45, Citizen Kant wrote: I'm trying to figure out the rules on how to recognize when a combination of symbols is considered a well formed expression in Python. Since I couldn't find any doc that lists all Python syntax rules Start by going to the Python website, www.python.org.

Re: [Tutor] Python "well-formed formulas"

2013-05-28 Thread Citizen Kant
2013/5/28 Dave Angel > On 05/28/2013 08:20 AM, Walter Prins wrote: > >> Hi, >> >> On 28 May 2013 12:44, Citizen Kant wrote: >> >> Could you please help me with a simple example of a Python well-formed >>> formula in order to understand "well-formed formulas" and "formation >>> rules" >>> concep

Re: [Tutor] Python "well-formed formulas"

2013-05-28 Thread Dave Angel
On 05/28/2013 08:20 AM, Walter Prins wrote: Hi, On 28 May 2013 12:44, Citizen Kant wrote: Could you please help me with a simple example of a Python well-formed formula in order to understand "well-formed formulas" and "formation rules" concepts properly? I'm assuming you perhaps meant "we

Re: [Tutor] Python "well-formed formulas"

2013-05-28 Thread Steven D'Aprano
On 28/05/13 21:44, Citizen Kant wrote: Could you please help me with a simple example of a Python well-formed formula in order to understand "well-formed formulas" and "formation rules" concepts properly? Probably not, since they aren't really Python terms, so I'll be guessing what they are.

Re: [Tutor] Python "well-formed formulas"

2013-05-28 Thread Walter Prins
Hi, On 28 May 2013 12:44, Citizen Kant wrote: > Could you please help me with a simple example of a Python well-formed > formula in order to understand "well-formed formulas" and "formation rules" > concepts properly? > I'm assuming you perhaps meant "well-formed expression". If so, here's a u

[Tutor] Python "well-formed formulas"

2013-05-28 Thread Citizen Kant
Could you please help me with a simple example of a Python well-formed formula in order to understand "well-formed formulas" and "formation rules" concepts properly? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: ht

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread Dave Angel
On 05/28/2013 07:02 AM, Jim Mooney wrote: On 27 May 2013 16:20, Alan Gauld wrote: To me, the bytecodes are the literal hex values corresponding to the Python "assembler" statements. Are you sure you need the bytecodes? You can use the standard library to generate the assembler listing from th

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread Jim Mooney
On 27 May 2013 16:32, Steven D'Aprano wrote: > On 28/05/13 06:01, Jim Mooney wrote: > Shall we guess what package that is? I love guessing games! > > Ah, who am I kidding. No I don't. > Well, I would hate to keep you guessing ;') It's called decompyle - pip couldn't find it, though, and it requi

Re: [Tutor] bytecode primer, and avoiding a monster download

2013-05-28 Thread Jim Mooney
On 27 May 2013 16:20, Alan Gauld wrote: > > To me, the bytecodes are the literal hex values corresponding > to the Python "assembler" statements. Are you sure you need the bytecodes? > You can use the standard library to generate the > assembler listing from the Python code. Ah good, how do I do

Re: [Tutor] a little loop

2013-05-28 Thread Alan Gauld
On 28/05/13 04:54, Tim Hanson wrote: x=0; ham=''; b=['s','p','a','m'] #or, b=('s','p','a','m') for t in b: ham=ham+b[x] print(ham);x+=1 Alright, it works, eventually. Can someone help me find a little more elegant way of doing this? I'm sure there are several. Python 'for