Re:Show HN: SpaceX Dragon simulator docking autopilot in Clo...
by yreg on Thursday May 21, 2020 @10:40AM
(#23258897)
Anything is a oneliner when you erase all the `\n`s
[ Parent
| on HN ]
Re:Show HN: SpaceX Dragon simulator docking autopilot in Clo...
by jylam on Thursday May 21, 2020 @11:07AM
(#23259248)
Python begs to differ
Re:Show HN: SpaceX Dragon simulator docking autopilot in Clo...
by vulcan01 on Thursday May 21, 2020 @01:48PM
(#23261943)
You can add semicolons at the end of python lines to replace \n's when calling from the command line.
python3 -c "n=1;print(n)"
Re:Show HN: SpaceX Dragon simulator docking autopilot in Clo...
by pferde on Thursday May 21, 2020 @02:00PM
(#23262193)
How does it deal with code blocks normally defined by indentation? (As an aside, indentation being part of syntax is the only thing keeping me disgusted with python - I like the language otherwise.)
Re:Show HN: SpaceX Dragon simulator docking autopilot in Clo...
by uryga on Thursday May 21, 2020 @03:14PM
(#23263521)
it doesn't :) though it works fine if your terminal allows multiline input:
python -c "
for x in stuff:
this(x)
that(x)
"
at some point i even wrote a hacky little wrapper that let you use braces and replaced¹ them with spaces+newlines, something like this: pyc-wrap "for x in stuff { this(x); that(x); }"
i can dig the code up if you need it :)========
though after that i sort of went of the deep end adding perl-style "it" ($_) variables for loop variables:
for stuff { this($); that($);
(yes, closing braces at the end were optional...)and for the result of the previous line:
2; $+1; hex($);
# roughly translates to:
x = 2; x = x+1; x = hex(x);
surprisingly pleasant to use for shell-like tasks actually!edit: almost forgot - if during execution you used a name `foo` not found in locals/globals, `foo` was treated as an external command, and resolved to something like
lambda *args: os.system('foo', *args)
so that you could (sorta) easily call external commands. fun times :)---
¹ slightly more involved than a dumb code.replace('{', ':\n') because you need to maintain the indent level... but around that level of sophistication