[Python-ideas] YAML (yet-another-multiline-lambda)

Andrew Barnert abarnert at yahoo.com
Thu Oct 24 04:19:55 CEST 2013


On Oct 23, 2013, at 5:50, Steven D'Aprano <steve at pearwood.info> wrote:

>> 
>> Write code that's somewhat readable and looks somewhat like Python?
> 
> No, that's not it. You can certainly write somewhat readable code that 
> looks like Python using type. But definition, calls to type() look like 
> Python code, because they *are* Python code.

Not everything that is executable as python looks like python. That's why we have the word "pythonic". Defining a class by building a dict to pass to the type function is not the way you define classes in Python, except in uncommon cases where you need to create classes based on dynamic information. Suggesting that it should be the idiomatic way of creating "local" or "inline" classes is like suggesting that exec('='.join(map(chr,range(97,40,-47)))) or locals().update(dict([map(chr,range(97,40,-47))])) or something should be the idiomatic way to assign 2 to x in some context. (After all, the only semantic difference is a minor scope-related issue--if this is the only assignment to x in a scope the compiler won't be able to tell that it's a local variable.)

Unless this is a roundabout way of arguing that there shouldn't be an idiomatic way to define inline classes in the first place?


More information about the Python-ideas mailing list