Live data from Hacker News

Convert any Python file into a single line of code

github.com

11–20 of 27 posts

Re: Convert any Python file into a single line of code

#13
+1 for the amusing faq. And I think this is a cool project. I'll use it just to learn better ways to make one-liners for use in other shell scripts and makefiles. Python has always been harder than the other languages I know to make one-liners, but on occasion it's quite useful.

Re: Convert any Python file into a single line of code

#15

Earlier quoted context omitted.

Brrring

haha, I think the resulting one liners are a little over 80 characters :)

Eh, you can insert newlines wherever you want and it'll still work, plus the "80 char line" rule is at the top of the list of PEP8 rules you can break.

Re: Convert any Python file into a single line of code

#16
post #13

+1 for the amusing faq. And I think this is a cool project. I'll use it just to learn better ways to make one-liners for use in other shell scripts and makefiles. Python has always been harder than the other languages I know to make one-liners, but on occasion it's quite useful.

On what occasion would a one-liner be useful? I'm genuinely curious, because I can't think of any such case, but I wouldn't doubt there being a few.

Re: Convert any Python file into a single line of code

#17
post #3

For a very limited definition of "any python file". Still brings me back to highschool, where we toyed with that kind of tricks (someone builds something, the others try to figure out how it works). Fun times!

Yeah, like trying to do a C file without semicolons

Re: Convert any Python file into a single line of code

#18
post #16
post #13

+1 for the amusing faq. And I think this is a cool project. I'll use it just to learn better ways to make one-liners for use in other shell scripts and makefiles. Python has always been harder than the other languages I know to make one-liners, but on occasion it's quite useful.

On what occasion would a one-liner be useful? I'm genuinely curious, because I can't think of any such case, but I wouldn't doubt there being a few.

Read the previous sentence :)

Re: Convert any Python file into a single line of code

#19
post #16
post #13

+1 for the amusing faq. And I think this is a cool project. I'll use it just to learn better ways to make one-liners for use in other shell scripts and makefiles. Python has always been harder than the other languages I know to make one-liners, but on occasion it's quite useful.

On what occasion would a one-liner be useful? I'm genuinely curious, because I can't think of any such case, but I wouldn't doubt there being a few.

Command line use. You grep some files, and think, "man, this really needs this ONE LITTLE FILTER". So, you pipe it to `perl -e "..."`, and soon have a very short program that you iterate on a few times to make sure you have right, and then you pipe it through the rest of the toolchain.

I don't write Perl much anymore, but that was far and away my __favorite__ way to use it. I love coding in Python now, more than I ever liked programming in any language (except perhaps lisp), but I still don't feel I can use it on the command line that way.

In the context of a Python program, I can't see the value of a Lovecraftian lambda (unless maybe in code golf comments?), but I found this article very appealing mainly because it's quite a feat. Doing anything nontrivial in a lambda is a pain in the ass, so the fact that someone wrote a tool to do it is awesome.

Post reply on HN