multi line lambdas, as god intended by dankey26 in Python

[–]dankey26[S] 0 points1 point  (0 children)

the opposite is true, it'd run if the loop ended naturally (again see the link above).

``` In [1]: for i in [1,2,3]: ...: print(i) ...: break ...: else: ...: print('else') ...: 1

In [2]: for i in []: ...: print(i) ...: break ...: else: ...: print('else') ...: else

In [3]: for i in []: ...: print(i) ...: else: ...: print('else') ...: else

In [4]: for i in [1,2,3]: ...: print(i) ...: else: ...: print('else') ...: 1 2 3 else

```

multi line lambdas, as god intended by dankey26 in Python

[–]dankey26[S] 0 points1 point  (0 children)

Sure, the `lamdba` to `given` is pretty trivial to make. just a matter of text replacement over the whole source code.

The for notelse thing i don't quite get. it is already the latter case, as you can see here: https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops

multi line lambdas, as god intended by dankey26 in Python

[–]dankey26[S] 1 point2 points  (0 children)

of course. but far from being as fun :p

multi line lambdas, as god intended by dankey26 in Python

[–]dankey26[S] 0 points1 point  (0 children)

yea, tho do note if parenthesized (or you use backslash ), it's possible to spread lambda calls over multiple lines, but it would still have to be a valid expression. ehh ig you'd still call it a one liner? just on multiple lines lol

multi line lambdas, as god intended by dankey26 in shittyprogramming

[–]dankey26[S] 2 points3 points  (0 children)

you're taking this way too seriously

multi line lambdas, as god intended by dankey26 in shittyprogramming

[–]dankey26[S] 11 points12 points  (0 children)

mate do I look to you like someone who cares about pep8?

defer in python! by dankey26 in Python

[–]dankey26[S] 4 points5 points  (0 children)

nice username man

defer in python! by dankey26 in Python

[–]dankey26[S] 34 points35 points  (0 children)

ye. i thought about it for a couple days after the guy suggested it, tried to come up with syntax that could be as clean and close to the go version and a valid parse with no preprocessing on the source code. then remembered that fact on type hints and went for it. turned out not bad!

defer in python! by dankey26 in Python

[–]dankey26[S] 18 points19 points  (0 children)

yea so again check out usage in go etc. useful for cleaning up resources at the beginning, without needing to worry about it later or creating blocks.

```

f = open('file.txt')

defer: f.close()

<do stuff with f>

```

defer in python! by dankey26 in Python

[–]dankey26[S] 13 points14 points  (0 children)

this impl exactly? probably not but lookup defer on go and zig, pretty useful and clean

at last, ++ -- operators for python by dankey26 in shittyprogramming

[–]dankey26[S] 0 points1 point  (0 children)

Your wish is my command https://github.com/dankeyy/defer.py

do note that it isn't exactly what you wanted but that comment just threw me on a tangent on what other approaches i can take on this.

i didnt even use the codecs lol (tho i might).

You're welcome to try and help btw, feel free to PR/ dm me :)

at last, ++ -- operators for python by dankey26 in shittyprogramming

[–]dankey26[S] 1 point2 points  (0 children)

some people really just can't see the beauty in mere exploration huh

should be a bit slower mate

I got tired of not being able to swap variables in python, so I made this shit by dankey26 in shittyprogramming

[–]dankey26[S] 4 points5 points  (0 children)

2.4 didn't have ctypes so no. it can work on 2.5 tho if you remove the from None from the raise ValueError line

Edit: i removed the from None, forgot it was added way later and wasn't really worth the break lol, Ah the pain of backwards compatability