Teaching Programming
superpollo
utente at esempio.net
Wed May 5 18:10:52 EDT 2010
Martin P. Hellwig ha scritto:
> On 05/04/10 12:59, superpollo wrote:
>> Martin P. Hellwig ha scritto:
> <cut>
>>> For the corner cases (I can think of a couple) it is good to know you
>>> can use ';' most of the time.
>>>
>>
>> most but not always as i noted (think about loops or function definition)
>>
> Well through in some exec magic then, for example:
> for number in [1,2,3,4]:
> def nprint(number):
> print(number)
> number += 1
> nprint(number
>
> translates to:
>
> >>> exec('for number in [1,2,3,4]:\n\tdef
> nprint(number):\n\t\tprint(number)\n\tnumber += 1\n\tnprint(number)')
> 2
> 3
> 4
> 5
>
> But if you have an example why indentation is still a problem please
> give it :-)
>
i think your exec example solved most of my problems. thanks a lot.
bye
More information about the Python-list
mailing list