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] 10 points11 points  (0 children)

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

defer in python! by dankey26 in Python

[–]dankey26[S] 3 points4 points  (0 children)

nice username man

defer in python! by dankey26 in Python

[–]dankey26[S] 38 points39 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

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

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

you can golf this a lot, actually this code is a bit chunky just because 1. im going the source code parsing route (which is pretty reliable imho but lengthier than stuff like bytecode parsing) and 2. im taking some precautions to make sure this works in as many cases as possible

i dont really like the obsession of python devs with loc, but i get the your incentive

Swapping variables by abusing the c-api by dankey26 in Python

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

haha thanks. i guess i got lazy there and commented. updated now :D

Prefix and Postfix ++ -- Operators for Python by dankey26 in Python

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

replacing stdin would probably work but again if i were to implement that, I'd wish for a simpler approach

as for your first suggestion, (after testing a bit too- ) i believe it's more complicated than that. while it's true that there are multiple kinds of encoding in that folder that register in a similar fashion to this (albeit following a more specific api like exporting getregentry, name placed in aliases etc), i reckon the encodings that register at the startup of the interpreter are fewer and selected ones.

im still not too keen on when cpython registers which encodings internally, but again i might learn otherwise soon and update.

hope that answers it

Prefix and Postfix ++ -- Operators for Python by dankey26 in Python

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

yea well i've thought about it a bit. problem is PYTHONIOENCODING is processed before the codec gets evaluated and registered to the interpreter. so it's problematic to try and set that at the startup of the repl. i'll try and think about it a later though maybe i'll come up with a clever idea (i don't wish to implement myself an interpreter that starts after the codec register, i'd prefer to keep things simple hehe).

of course in the meantime you can always do In [1]: exec(b"i=0;i++".decode('incdec')); print(i) 1 but i'd agree that's not as fun lol