3 ms·
Python begs to differ
by jylam 6y ago
Python begs to differ
- vulcan01 6y agoYou 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)"
- pferde 6y agoHow 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.)
- uryga 6y agoit 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