On Tue, May 4, 2010 at 7:23 AM, superpollo <ute...@esempio.net> wrote:
> 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

Well, it requires 2.6 or 3

Python 2.6.5 (r265:79063, Mar 21 2010, 22:38:52)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function
>>> A,B=2,3;print(A+B if A > B else A**B - B**2)
-1
>>> A,B=3,2;print(A+B if A > B else A**B - B**2)
5

>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to