I tried a few (not all) of the examples with plain old Python (granted, these are multi-liners, not one-liners, but I think they're easier to read). I'm not sure I see the advantange of curly braces.<p><pre><code> # --- Example 1
# pwk
pwk 'if "braces"=="bad": { print("Be gone!"); exit(99) } else: { print("Howdy!") }'
# vs
# python
python -c 'if "braces"=="bad": print("Be gone!"); exit(99)
else: print("Howdy!")'
# --- Example 2
pwk 'def s2i(s): { return int(s) } print(s2i("41")+1)'
python -c 'def s2i(s): return int(s)
print(s2i("41")+1)'
# --- Example 3
ls / | pwk 'for s in sys.stdin: try: { print(os.listdir("/"+s.strip())) } except: pass'
ls / | python -c 'import sys, os
for s in sys.stdin:
try: print(os.listdir("/"+s.strip()))
except: pass'</code></pre>
Face it - Python just ain't fit for one-liners. Give Perl and Ruby some credit as they were designed for conciseness and the command-line. Python may dominate data science, AI and ML but it's deficiencies bleed through when you try to compose something elegant and concise.
I really don't understand the love of one liners. Yes it's cool to see how much can be done in one line but it's so much harder to read. Isn't legibility far better than compactness?
> (To the best of my knowledge, there is as of 2020 no purely pythonic way to write one-lined try-blocks.)<p>You can do this using contexlib. For example the following in pwk:<p><pre><code> try: { print(os.listdir("/"+s.strip())) } except: pass
</code></pre>
Can be written in pure Python as:<p><pre><code> with contextlib.suppress(Exception): print(os.listdir("/"+s.strip()))
</code></pre>
(Assuming contextlib is imported, and you're okay with letting things which don't extend Exception slip through.)<p>You could probably also make a context manager which takes a function/lambda to define how to handle exceptions etc.
It's a shame Python doesn't natively support easy invocation from command line. It really shoots down a whole class of applications where bash is getting used but Python would be so much better.<p>I've ended up using Groovy for this level of scripting, and it works really well.
In a similar vein, pyp: <a href="https://github.com/hauntsaninja/pyp" rel="nofollow">https://github.com/hauntsaninja/pyp</a>
> Python With Kurly braces<p>I wasn't aware of this. I guess it might silence a few critics.<p>However I'd be much more interested to try "Javascript with semantic white space"
There is also Bython: <a href="https://github.com/mathialo/bython" rel="nofollow">https://github.com/mathialo/bython</a>
I like python and I enjoy weirdo one-off languages, so I'm predisposed to like this. But why keep the colons? It would look nicer without.<p>...<p>I just attempted to type out an example and found a reason not to do this... it's the same reason c needs parentheses around the conditional. On the balance, I prefer parentheses over the vestigial colon.
been done a while ago by forking Python (2.7.6)and modifying the grammar: <a href="http://python-with-braces.appspot.com/" rel="nofollow">http://python-with-braces.appspot.com/</a>
This meaningful whitespace thing in python is dreck. Hate it. I am not a python hater; this is from experience on projects (though this is now less of a problem because of IDE help). I like python and I choose it for my personal projects. I will probably use this.
> Just download and chmod it<p>No source? No thanks.<p>Edit: Discard this comment! I thought pwk in the repo was an executable because it did not have a ".py" ending and did not care to check. Sorry!