Teaching Programming

superpollo utente at esempio.net
Tue May 4 07:23:56 EDT 2010


Stefan Behnel ha scritto:
> superpollo, 04.05.2010 12:28:
>> i think there is an issue if you -- say -- produce python code, from
>> within another programming environment, to be executed on the fly, at
>> least in some instances. there might be problems if for example you
>> generate code from a one-line template.
> 
> There are a couple of code generation tools available that you can find 
> on PyPI.
> 
> However, the main reason why this problem doesn't hurt much in Python is 
> that Python is a dynamic language that can get you extremely far without 
> generating code. It's simply not necessary in most cases, so people 
> don't run into problems with it.
> 
> Stefan
> 

Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> A,B=2,3
 >>> if A>B:
...     print A+B
... else:
...     print A**B-B**2
...
-1
 >>> A,B=3,2
 >>> if A>B:
...     print A+B
... else:
...     print A**B-B**2
...
5
 >>>

tell me please: how can generate the same output (depending on A and B) 
without control structure? i mean in a natural "pythonic" way...

bye




More information about the Python-list mailing list